package compat
Implicit conversions for handler & 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._ def foo(v: BSONValue): JsValue = v // ValueConverters.fromValue
For more specific imports, see ValueConverters and HandlerConverters.
- Alphabetic
- By Inheritance
- compat
- HandlerConverters
- LowPriorityHandlerConverters1
- LowPriorityHandlerConverters2
- LowPriorityHandlerConverters3
- ValueConverters
- LowPriority1Converters
- SharedValueConverters
- SharedValueConvertersLowPriority1
- PackageCompat
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- trait HandlerConverters extends LowPriorityHandlerConverters1
Implicit conversions for handler types between
play.api.libs.json
andreactivemongo.api.bson
.Implicit conversions for handler types between
play.api.libs.json
andreactivemongo.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. - trait ValueConverters extends SharedValueConverters with LowPriority1Converters
Implicit conversions for value types between
play.api.libs.json
andreactivemongo.api.bson
.Implicit conversions for value types between
play.api.libs.json
andreactivemongo.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.
Value Members
- val JsFalse: play.api.libs.json.JsFalse.type
Compatibility alias for
play.api.libs.json.JsFalse
(DO NOT USE)Compatibility alias for
play.api.libs.json.JsFalse
(DO NOT USE)- Definition Classes
- PackageCompat
- val JsTrue: play.api.libs.json.JsTrue.type
Compatibility alias for
play.api.libs.json.JsTrue
(DO NOT USE)Compatibility alias for
play.api.libs.json.JsTrue
(DO NOT USE)- Definition Classes
- PackageCompat
- implicit def fromArray(bson: BSONArray): JsArray
- Definition Classes
- SharedValueConverters
- implicit final def fromBinary(bin: BSONBinary): JsObject
See syntax:
See syntax:
{ "$binary": { "base64": "<payload>", "subType": "<t>" } }
- Definition Classes
- SharedValueConverters
- implicit final def fromBoolean(bson: BSONBoolean): JsBoolean
- Definition Classes
- SharedValueConverters
- implicit final def fromDateTime(bson: BSONDateTime): JsObject
See syntax:
See syntax:
{ "$date": { "$numberLong": "<millis>" } }
- Definition Classes
- SharedValueConverters
- implicit final def fromDecimal(bson: BSONDecimal): JsObject
See syntax:
See syntax:
{ "$numberDecimal": "<number>" }
- Definition Classes
- SharedValueConverters
- implicit def fromDocument(bson: BSONDocument): JsObject
Converts to a JSON object
Converts to a JSON object
- Definition Classes
- SharedValueConverters
- implicit final def fromDocumentHandler[T](h: BSONDocumentHandler[T]): OFormat[T]
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 }
- Definition Classes
- HandlerConverters
- implicit final def fromDocumentReader[T](r: BSONDocumentReader[T]): Reads[T]
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 }
- Definition Classes
- LowPriorityHandlerConverters2
- implicit final def fromDocumentWriter[T](w: BSONDocumentWriter[T]): OWrites[T]
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 }
- Definition Classes
- LowPriorityHandlerConverters2
- implicit final def fromDouble(bson: BSONDouble): JsNumber
- Definition Classes
- ValueConverters
- implicit final def fromHandler[T](h: BSONHandler[T]): Format[T]
- Definition Classes
- LowPriorityHandlerConverters1
- implicit final def fromInteger(bson: BSONInteger): JsNumber
- Definition Classes
- ValueConverters
- implicit final def fromJavaScript(bson: BSONJavaScript): JsObject
See syntax:
See syntax:
{ "$code": "<javascript>" }
- Definition Classes
- SharedValueConverters
- implicit final def fromJavaScriptWS(bson: BSONJavaScriptWS): JsObject
See syntax:
See syntax:
{ "$code": "<javascript>", "$scope": { } }
- Definition Classes
- SharedValueConverters
- implicit final def fromLong(bson: BSONLong): JsNumber
- Definition Classes
- ValueConverters
- implicit final val fromMaxKey: (BSONMaxKey) => JsObject
See syntax:
See syntax:
{ "$maxKey": 1 }
- Definition Classes
- SharedValueConverters
- implicit final val fromMinKey: (BSONMinKey) => JsObject
See syntax:
See syntax:
{ "$minKey": 1 }
- Definition Classes
- SharedValueConverters
- implicit val fromNull: (BSONNull) => JsNull.type
- Definition Classes
- SharedValueConverters
- implicit final def fromObject(js: JsObject): BSONValue
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.- Definition Classes
- SharedValueConverters
- implicit final def fromObjectID(bson: BSONObjectID): JsObject
See syntax:
See syntax:
{ "$oid": "<ObjectId bytes>" }
- Definition Classes
- SharedValueConverters
- implicit final def fromReader[T](r: BSONReader[T]): Reads[T]
- Definition Classes
- LowPriorityHandlerConverters3
- implicit final def fromRegex(rx: BSONRegex): JsObject
See syntax:
See syntax:
{ "$regularExpression": { "pattern": "<regexPattern>", "options": "<options>" } }
- Definition Classes
- SharedValueConverters
- implicit final def fromStr(bson: BSONString): JsString
- Definition Classes
- SharedValueConverters
- implicit final def fromSymbol(bson: BSONSymbol): JsObject
See syntax:
See syntax:
{ "$symbol": "<name>" }
- Definition Classes
- SharedValueConverters
- implicit final def fromTimestamp(ts: BSONTimestamp): JsObject
See syntax:
See syntax:
{ "$timestamp": {"t": <t>, "i": } }`
- Definition Classes
- SharedValueConverters
- implicit final val fromUndefined: (BSONUndefined) => JsObject
See syntax:
See syntax:
{ "$undefined": true }
- Definition Classes
- SharedValueConverters
- implicit final def fromValue(bson: BSONValue): JsValue
- Definition Classes
- LowPriority1Converters
- implicit final def fromWriter[T](w: BSONWriter[T]): Writes[T]
- Definition Classes
- LowPriorityHandlerConverters3
- implicit def jsonReaderNewValue[B <: BSONValue, L](implicit r: BSONDocumentReader[B], conv: (B) => L): Reads[L]
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.- Definition Classes
- HandlerConverters
- implicit def jsonWriterNewValue[B <: BSONValue, L](implicit w: BSONDocumentWriter[B], conv: (L) => B): OWrites[L]
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.- Definition Classes
- HandlerConverters
- implicit final def toArray(js: JsArray): BSONArray
- Definition Classes
- SharedValueConverters
- implicit final def toBoolean(js: JsBoolean): BSONBoolean
- Definition Classes
- SharedValueConverters
- implicit final def toDocument(js: JsObject): BSONDocument
See toValue
See toValue
- Definition Classes
- SharedValueConvertersLowPriority1
- implicit final def toDocumentHandler[T](h: OFormat[T]): BSONDocumentHandler[T]
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 }
- Definition Classes
- HandlerConverters
- implicit final def toDocumentReader[T](implicit r: Reads[T]): BSONDocumentReader[T]
Provided there is a Play JSON
Reads
, resolve a new one.Provided there is a Play JSON
Reads
, resolve a new one.- Definition Classes
- LowPriorityHandlerConverters3
- implicit final def toDocumentReaderConv[T](r: Reads[T]): BSONDocumentReader[T]
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 }
- Definition Classes
- LowPriorityHandlerConverters3
- implicit final def toDocumentWriter[T](implicit w: OWrites[T]): BSONDocumentWriter[T]
Provided there is a Play JSON
OWrites
, resolve a new one.Provided there is a Play JSON
OWrites
, resolve a new one.- Definition Classes
- LowPriorityHandlerConverters2
- implicit final def toDocumentWriterConv[T](w: OWrites[T]): BSONDocumentWriter[T]
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 }
- Definition Classes
- LowPriorityHandlerConverters2
- implicit final def toHandler[T](h: Format[T]): BSONHandler[T]
- Definition Classes
- LowPriorityHandlerConverters1
- implicit val toNull: (JsNull.type) => BSONNull
- Definition Classes
- SharedValueConverters
- implicit final def toNumber(js: JsNumber): BSONValue
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).
- Definition Classes
- SharedValueConverters
- implicit final def toReader[T](r: Reads[T]): BSONReader[T]
- Definition Classes
- LowPriorityHandlerConverters2
- implicit final def toStr(js: JsString): BSONValue
- Definition Classes
- SharedValueConverters
- implicit final def toValue(js: JsValue): BSONValue
- Definition Classes
- SharedValueConvertersLowPriority1
- implicit final def toWriter[T](w: Writes[T]): BSONWriter[T]
- Definition Classes
- LowPriorityHandlerConverters3
- object ExtendedJsonConverters extends ExtendedJsonCompat with SharedValueConverters with LowPriority1ExtendedJson
- object HandlerConverters extends HandlerConverters
See compat$ and HandlerConverters
- object JavaScriptObject
See syntax
See syntax
- Definition Classes
- SharedValueConverters
- object JavaScriptWSObject
See syntax
See syntax
- Definition Classes
- SharedValueConverters
- object ValueConverters extends ValueConverters
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). - object dsl
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" } // }