Implicit conversions for handler types
between play.api.libs.json
and reactivemongo.api.bson
.
Implicit conversions for handler types
between play.api.libs.json
and reactivemongo.api.bson
.
import reactivemongo.play.json.compat.HandlerConverters._ def foo[T](jw: play.api.libs.json.OWrites[T]) = { val w: reactivemongo.api.bson.BSONDocumentWriter[T] = jw w } def bar[T](br: reactivemongo.api.bson.BSONReader[T]) = { val r: play.api.libs.json.Reads[T] = br r }
Note: Logger reactivemongo.api.play.json.HandlerConverters
can be used to debug.
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.
See compat$ and HandlerConverters
See syntax
See syntax
See syntax
See syntax
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)
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).
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:
{ "$numberDecimal": "<number>" }
Converts to a JSON object
Converts to a JSON object
Implicit conversion from new BSONDocumentHandler
to Play JSON.
Implicit conversion from new BSONDocumentHandler
to Play JSON.
import reactivemongo.play.json.compat.HandlerConverters.fromDocumentHandler def bar[T](bh: reactivemongo.api.bson.BSONDocumentHandler[T]) = { val h: play.api.libs.json.OFormat[T] = bh h }
import reactivemongo.play.json.compat.HandlerConverters.fromDocumentReader def foo[T](r: reactivemongo.api.bson.BSONDocumentReader[T]) = { val jr: play.api.libs.json.Reads[T] = r jr }
import reactivemongo.play.json.compat.HandlerConverters.fromDocumentWriter def bar[T](lw: reactivemongo.api.bson.BSONDocumentWriter[T]) = { val w: play.api.libs.json.OWrites[T] = lw w }
See syntax:
See syntax:
{ "$code": "<javascript>" }
See syntax:
See syntax:
{
"$code": "<javascript>",
"$scope": { }
}
See syntax:
See syntax:
{ "$maxKey": 1 }
See syntax:
See syntax:
{ "$minKey": 1 }
First checks whether an explicit type (e.g.
First checks whether an explicit type (e.g. $binary
) is specified,
otherwise converts to a BSON document.
See syntax:
See syntax:
{ "$oid": "<ObjectId bytes>" }
See syntax:
See syntax:
{ "$regularExpression":
{
"pattern": "<regexPattern>",
"options": "<options>"
}
}
See syntax:
See syntax:
{ "$symbol": "<name>" }
See syntax:
See syntax:
{ "$timestamp": {"t": <t>, "i": } }`
See syntax:
See syntax:
{ "$undefined": true }
Based on the compatibility conversions,
provides instances of Play JSON Reads
for the new BSON value API.
Based on the compatibility conversions,
provides instances of Play JSON Reads
for the new BSON value API.
Based on the compatibility conversions,
provides instances of Play JSON OWrites
for the new BSON value API.
Based on the compatibility conversions,
provides instances of Play JSON OWrites
for the new BSON value API.
See toValue
See toValue
Implicit conversion from Play JSON OFormat
to the BSON API.
Implicit conversion from Play JSON OFormat
to the BSON API.
import reactivemongo.play.json.compat.HandlerConverters.toDocumentHandler def foo[T](jh: play.api.libs.json.OFormat[T]) = { val h: reactivemongo.api.bson.BSONDocumentHandler[T] = jh h }
Provided there is a Play JSON Reads
, resolve a new one.
Provided there is a Play JSON Reads
, resolve a new one.
import reactivemongo.play.json.compat.HandlerConverters.toDocumentReaderConv def lorem[T](jr: play.api.libs.json.Reads[T]) = { val w: reactivemongo.api.bson.BSONDocumentReader[T] = jr w }
Provided there is a Play JSON OWrites
, resolve a new one.
Provided there is a Play JSON OWrites
, resolve a new one.
import reactivemongo.play.json.compat.HandlerConverters.toDocumentWriterConv def foo[T](jw: play.api.libs.json.OWrites[T]) = { val w: reactivemongo.api.bson.BSONDocumentWriter[T] = jw w }
If the number:
If the number:
- is not whole then it's converted to BSON double, - is a valid integer then it's converted to a BSON integer (int32), - otherwise it's converted to a BSON long integer (int64).
Implicit conversions for handler & value types between
play.api.libs.json
andreactivemongo.api.bson
.For more specific imports, see ValueConverters and HandlerConverters.