public class Json extends Object
BSON Type | Class | Format | Example |
---|---|---|---|
Symbol | Symbol |
"value" | "The quick brown fox" |
Regular Expression | Pattern |
{ "$regex" : "pattern", "$otions" : "flags" } | { "$regex" : "[CH]at\sin", "$options" : "im" } |
Date | Date |
{ "$date" : "yyyy-MM-ddTHH:mm:ssZ" } | { "$date" : "2011-06-11T08:44:25Z" } |
Timestamp | Timestamp |
{ "$ts" : timeValue, "$inc" : incValue } | "\/TS("2011-06-11T08:44:25Z")\/" |
ObjectId | ObjectId |
{ "$oid" : "12bytesOfIdInBase16" } | { "$oid" : "0000012c0000c8000900000f" } |
Binary | Binary |
{ "$type" : typeAsInt, "$base64" : "bytesInBase64" }" | { "$type" : 0, "$base64" : "TWFuIGlzIGRpc3R" }" |
UUID | UUID |
{ "$uuid" : "string-form-of-uuid" } | { "$uuid" : "09e0e949-bba4-459c-bb1d-9352e5ee8958" } |
Code | Code |
{ "$code" : "code" } | { "$code" : "244-I2" } |
CodeWithScope | CodeWithScope |
{ "$code" : "code", "$scope" : scope document } | { "$code" : "244-I2", "$scope" : { "name" : "Joe" } } |
MinKey | MinKey |
"MinKey" | "MinKey" |
MaxKey | MaxKey |
"MaxKey" | "MaxKey" |
Null value | n/a | null | null |
Modifier and Type | Class and Description |
---|---|
class |
Json.ReservedField
A set of field names that are reserved for special formatting of non-standard JSON value types as nested objects.
|
Constructor and Description |
---|
Json() |
Modifier and Type | Method and Description |
---|---|
protected static JsonWriter |
getCompactJsonWriter() |
protected static JsonWriter |
getPrettyWriter() |
protected static JsonReader |
getReader() |
static Document |
read(InputStream stream)
Read the JSON representation from supplied input stream and construct the
Document representation, using the
default character set . |
static Document |
read(InputStream stream,
Charset charset)
Read the JSON representation from supplied input stream and construct the
Document representation, using the
supplied character set . |
static Document |
read(Reader reader)
Read the JSON representation from supplied input stream and construct the
Document representation. |
static Document |
read(String json)
Read the supplied JSON representation and construct the
Document representation. |
static Document |
read(URL url)
Read the JSON representation from supplied URL and construct the
Document representation, using the
default character set . |
static DocumentSequence |
readMultiple(InputStream stream)
Return a
DocumentSequence that can be used to pull multiple documents from the stream. |
static DocumentSequence |
readMultiple(Reader reader)
Return a
DocumentSequence that can be used to pull multiple documents from the stream. |
static String |
write(Document bson)
Return the modified JSON representation for the supplied in-memory
Document . |
static void |
write(Document bson,
OutputStream stream)
Write to the supplied writer the modified JSON representation of the supplied in-memory
Document . |
static void |
write(Document bson,
Writer writer)
Write to the supplied writer the modified JSON representation of the supplied in-memory
Document . |
static String |
write(Object value)
Return the modified JSON representation for the supplied object value.
|
static String |
writePretty(Document bson)
Return the modified JSON representation for the supplied in-memory
Document . |
static void |
writePretty(Document bson,
OutputStream stream)
Write to the supplied writer the modified JSON representation of the supplied in-memory
Document . |
static void |
writePretty(Document bson,
Writer writer)
Write to the supplied writer the modified JSON representation of the supplied in-memory
Document . |
static String |
writePretty(Object value)
Return the modified JSON representation for the supplied object value.
|
protected static JsonWriter getCompactJsonWriter()
protected static JsonWriter getPrettyWriter()
protected static JsonReader getReader()
public static Document read(URL url) throws ParsingException
Document
representation, using the
default character set
.
This method will read standard JSON and modified JSON, and tolerates whitespace and use of several delimeters, including the standard ':' as well as '=' and '=>'.
url
- the URL of the JSON document; may not be null and must be resolvableDocument
representationParsingException
- if there was a problem reading from the streampublic static Document read(InputStream stream) throws ParsingException
Document
representation, using the
default character set
.
This method will read standard JSON and modified JSON, and tolerates whitespace and use of several delimeters, including the standard ':' as well as '=' and '=>'.
stream
- the input stream; may not be nullDocument
representationParsingException
- if there was a problem reading from the streampublic static Document read(InputStream stream, Charset charset) throws ParsingException
Document
representation, using the
supplied character set
.
This method will read standard JSON and modified JSON, and tolerates whitespace and use of several delimeters, including the standard ':' as well as '=' and '=>'.
stream
- the input stream; may not be nullcharset
- the character set that should be used; may not be nullDocument
representationParsingException
- if there was a problem reading from the streampublic static Document read(Reader reader) throws ParsingException
Document
representation.
This method will read standard JSON and modified JSON, and tolerates whitespace and use of several delimeters, including the standard ':' as well as '=' and '=>'.
reader
- the IO reader; may not be nullDocument
representationParsingException
- if there was a problem reading from the streampublic static Document read(String json) throws ParsingException
Document
representation.
This method will read standard JSON and modified JSON, and tolerates whitespace and use of several delimeters, including the standard ':' as well as '=' and '=>'.
json
- the JSON document string; may not be nullDocument
representationParsingException
- if there was a problem reading from the streampublic static DocumentSequence readMultiple(InputStream stream)
DocumentSequence
that can be used to pull multiple documents from the stream.stream
- the input stream; may not be nullpublic static DocumentSequence readMultiple(Reader reader)
DocumentSequence
that can be used to pull multiple documents from the stream.reader
- the IO reader; may not be nullpublic static String write(Document bson)
Document
. The resulting JSON will have no
embedded line feeds or extra spaces.
This format is compact and easy for software to read, but usually very difficult for people to read anything but very small documents.
bson
- the BSON object or BSON value; may not be nullpublic static String write(Object value)
This format is compact and easy for software to read, but usually very difficult for people to read anything but very small documents.
value
- the BSON object or BSON value; may not be nullpublic static void write(Document bson, Writer writer) throws IOException
Document
. The resulting
JSON will have no embedded line feeds or extra spaces.
This format is compact and easy for software to read, but usually very difficult for people to read anything but very small documents.
bson
- the BSON object or BSON value; may not be nullwriter
- the writer; may not be nullIOException
- if there was a problem reading from the streampublic static void write(Document bson, OutputStream stream) throws IOException
Document
. The resulting
JSON will have no embedded line feeds or extra spaces.
This format is compact and easy for software to read, but usually very difficult for people to read anything but very small documents.
bson
- the BSON object or BSON value; may not be nullstream
- the output stream; may not be nullIOException
- if there was a problem reading from the streampublic static String writePretty(Document bson)
Document
. The resulting JSON will be indented
for each name/value pair and each array value.
This format is very readable by people and software, but is less compact due to the extra whitespace.
bson
- the BSON object or BSON value; may not be nullpublic static String writePretty(Object value)
This format is very readable by people and software, but is less compact due to the extra whitespace.
value
- the BSON object or BSON value; may not be nullpublic static void writePretty(Document bson, Writer writer) throws IOException
Document
. The resulting
JSON will be indented for each name/value pair and each array value.
This format is very readable by people and software, but is less compact due to the extra whitespace.
bson
- the BSON object or BSON value; may not be nullwriter
- the writer; may not be nullIOException
- if there was a problem reading from the streampublic static void writePretty(Document bson, OutputStream stream) throws IOException
Document
. The resulting
JSON will be indented for each name/value pair and each array value.
This format is very readable by people and software, but is less compact due to the extra whitespace.
bson
- the BSON object or BSON value; may not be nullstream
- the output stream; may not be nullIOException
- if there was a problem reading from the streamCopyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.