Conversion API from BSON to JSON values
JSON representation for numbers
JSON representation for numbers
Conversion API from BSON to JSON values
Implicit conversions for value types between
play.api.libs.json
and reactivemongo.api.bson
.
Implicit conversions for value types between
play.api.libs.json
and reactivemongo.api.bson
.
import play.api.libs.json.JsValue import reactivemongo.api.bson.BSONValue import reactivemongo.play.json.compat.ValueConverters._ def foo(v: BSONValue): JsValue = implicitly[JsValue](v) // ValueConverters.fromValue def bar(v: JsValue): BSONValue = implicitly[BSONValue](v) // ValueConverters.toValue
Note: Logger reactivemongo.api.play.json.ValueConverters
can be used to debug.
Compatibility alias for play.api.libs.json.JsFalse
(DO NOT USE)
Compatibility alias for play.api.libs.json.JsFalse
(DO NOT USE)
Compatibility alias for play.api.libs.json.JsTrue
(DO NOT USE)
Compatibility alias for play.api.libs.json.JsTrue
(DO NOT USE)
Implicit conversions for value types between
play.api.libs.json
and reactivemongo.api.bson
,
using lax conversions.
See compat$ and ValueConverters.
See compat$ and ValueConverters.
Note that as there is not a JSON equivalent for each BSON value
(BSONDateTime
, or even distinction between BSON long/int).
So for example, using the default JSON handlers,
a same Long
property can be written in some documents
as BSON long (NumberLong
), and in some other as BSON integer
(see ValueConverters.toNumber), which is ok to read all these documents,
but can impact the MongoDB queries (same for date/time values that
will be serialized as BSON string, rather than BSON date/time or timestamp).
Implicit conversions for handler types
from reactivemongo.api.bson
to play.api.libs.json
.
Implicit conversions for handler types
from reactivemongo.api.bson
to play.api.libs.json
.
import reactivemongo.play.json.compat.bson2json._ def bar[T](br: reactivemongo.api.bson.BSONReader[T]) = { val r: play.api.libs.json.Reads[T] = br r }
Note: Importing both json2bson
& bson2json
can lead to diverging implicits in Scala 2.11
(see HandlerConverterSpec211
).
DSL for MongoDB Extended JSON syntax (v2).
DSL for MongoDB Extended JSON syntax (v2).
import play.api.libs.json.Json import reactivemongo.play.json.compat.dsl._ Json.obj("int" -> int(1), "double" -> double(2.3D)) // { // "int": { "$numberInt": "1" }, // "double": { "$numberDouble": "2.3" } // }
See syntax:
See syntax:
{ "$binary":
{
"base64": "<payload>",
"subType": "<t>"
}
}
See syntax:
See syntax:
{ "$date": { "$numberLong": "<millis>" } }
See syntax:
See syntax:
{
"$code": "<javascript>",
"$scope": { }
}
See syntax:
See syntax:
See syntax:
See syntax:
{ "$regularExpression":
{
"pattern": "<regexPattern>",
"options": "<options>"
}
}
See syntax:
See syntax:
{ "$timestamp": {"t": <t>, "i": } }`
See syntax:
Implicit conversions for handler types
from play.api.libs.json
to reactivemongo.api.bson
.
Implicit conversions for handler types
from play.api.libs.json
to reactivemongo.api.bson
.
import reactivemongo.play.json.compat.json2bson._ def foo[T](jw: play.api.libs.json.OWrites[T]) = { val w: reactivemongo.api.bson.BSONDocumentWriter[T] = jw w }
Note: Importing both json2bson
& bson2json
can lead to diverging implicits in Scala 2.11
(see HandlerConverterSpec211
).
import play.api.libs.json._ import reactivemongo.api.bson._ import reactivemongo.play.json.compat.lax._ Json.obj("_id" -> BSONObjectID.generate()) // objectIdWrites // { "_id": "as_string_instead_of_ObjectId" }
Implicit conversions for handler & value types between
play.api.libs.json
andreactivemongo.api.bson
, by default using the MongoDB Extended JSON syntax.For more specific imports, see ValueConverters and handler converters.