public class Json extends Object
Document
s and also serializing BSON Document
s into JSON text.
In addition to the basic JSON types the parser also supports the following standard MongoDB/BSON extensions:
BinaryElement
. The first field is the sub-type,
normally zero. The second field is the base64 encoded binary value: { a : BinData(0, "VVU=") }
or
{ a : { $binary:"VVU=", $type:0 } }
BinaryElement
. The first field is the sub-type,
normally zero. The second field is the hex encoded binary value: { a : HexData(0, "cafe") }
TimestampElement
: { a : ISODate("2012-07-14T01:00:00.000") }
or
{ a : { $date : "2012-07-14T01:00:00.000" } }
or
{ a : { $date : 1234567890 } }
MaxKeyElement
: { a : MaxKey }
or { a : MaxKey() }
MinKeyElement
: { a : MinKey }
or { a : MinKey() }
LongElement
: { a : NumberLong("123456789") }
ObjectIdElement
. The string is the hex encoding of the
128 bit value: { a : ObjectId("4e9d87aa5825b60b637815a6") }
or
{ a : { $oid : "4e9d87aa5825b60b637815a6" } }
RegularExpressionElement
: { a : { $regex : 'cat' , $options : 'i' } }
MongoTimestampElement
. The first value is the seconds
since the UNIX epoch. The second value is an ordinal: { a : Timestamp(0,0) }
or
{ a : { $timestamp : { t : 0, i : 0 } } }
The following non-standard extensions are also provided. These extensions may be deprecated in future releases if standard extensions are created:
DBPointerElement
:{ a : DBPointer("db", 'collection', ObjectId("4e9d87aa5825b60b637815a6") ) }
DBRef
convention
Note: Currently serialization/parsing round trip is not supported for
the following Element
types:
Modifier and Type | Method and Description |
---|---|
static Document |
parse(Reader input)
Parses the document from the reader into a BSON
Document . |
static Document |
parse(String input)
Parses the document from the reader into a BSON
Document . |
static String |
serialize(DocumentAssignable document)
Serializes the
Document to an equivalent JSON document. |
static void |
serialize(DocumentAssignable document,
Writer sink)
Serializes the
Document to an equivalent JSON document. |
public static Document parse(Reader input) throws JsonParseException
Document
.
See the class documentation for important limitations on round trip serialization and parsing.
input
- The source of the document to read.Document
representation of the JSON document.JsonParseException
- On a failure to parse the JSON document.public static Document parse(String input) throws JsonParseException
Document
.
This method is equivalent to:
parse(new StringReader(input));
See the class documentation for important limitations on round trip serialization and parsing.
input
- The source of the document to read.Document
representation of the JSON document.JsonParseException
- On a failure to parse the JSON document.public static String serialize(DocumentAssignable document) throws JsonException
Document
to an equivalent JSON document.
See the class documentation for important limitations on round trip serialization and parsing.
document
- The document to conver to a JSON document.JsonException
- On a failure to write the JSON document.public static void serialize(DocumentAssignable document, Writer sink) throws JsonException
Document
to an equivalent JSON document.
See the class documentation for important limitations on round trip serialization and parsing.
document
- The document to conver to a JSON document.sink
- The sink for the JSON document text.JsonException
- On a failure to write the JSON document.Copyright © 2011-2013 Allanbank Consulting, Inc.. All Rights Reserved.