Package org.bson.json
Class JsonWriter
- java.lang.Object
-
- org.bson.AbstractBsonWriter
-
- org.bson.json.JsonWriter
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,BsonWriter
public class JsonWriter extends AbstractBsonWriter
ABsonWriter
implementation that outputs a JSON representation of BSON.- Since:
- 3.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
JsonWriter.Context
The context for the writer, inheriting all the values fromAbstractBsonWriter.Context
, and additionally providing settings for the indentation level and whether there are any child elements at this level.-
Nested classes/interfaces inherited from class org.bson.AbstractBsonWriter
AbstractBsonWriter.Mark, AbstractBsonWriter.State
-
-
Constructor Summary
Constructors Constructor Description JsonWriter(Writer writer)
Creates a new instance which useswriter
to write JSON to.JsonWriter(Writer writer, JsonWriterSettings settings)
Creates a new instance which useswriter
to write JSON to and uses the given settings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
abortPipe()
Return true if the current execution of the pipe method should be aborted.protected void
doWriteBinaryData(BsonBinary binary)
Handles the logic of writing aBsonBinary
valuevoid
doWriteBoolean(boolean value)
Handles the logic of writing a boolean valueprotected void
doWriteDateTime(long value)
Handles the logic of writing a date time valueprotected void
doWriteDBPointer(BsonDbPointer value)
Handles the logic of writing a DbPointer valueprotected void
doWriteDecimal128(Decimal128 value)
Handles the logic of writing a Decimal128 valueprotected void
doWriteDouble(double value)
Handles the logic of writing a Double valueprotected void
doWriteEndArray()
Handles the logic of writing the end of an arrayprotected void
doWriteEndDocument()
Handles the logic of writing the end of a documentprotected void
doWriteInt32(int value)
Handles the logic of writing an int32 valueprotected void
doWriteInt64(long value)
Handles the logic of writing an int64 valueprotected void
doWriteJavaScript(String code)
Handles the logic of writing a JavaScript functionprotected void
doWriteJavaScriptWithScope(String code)
Handles the logic of writing a scoped JavaScript functionprotected void
doWriteMaxKey()
Handles the logic of writing a Max keyprotected void
doWriteMinKey()
Handles the logic of writing a Min keyprotected void
doWriteName(String name)
Handles the logic of writing the element name.void
doWriteNull()
Handles the logic of writing a Null valuevoid
doWriteObjectId(ObjectId objectId)
Handles the logic of writing an ObjectIdvoid
doWriteRegularExpression(BsonRegularExpression regularExpression)
Handles the logic of writing a regular expressionprotected void
doWriteStartArray()
Handles the logic to start writing an arrayprotected void
doWriteStartDocument()
Handles the logic to start writing a documentvoid
doWriteString(String value)
Handles the logic of writing a Stringvoid
doWriteSymbol(String value)
Handles the logic of writing a Symbolvoid
doWriteTimestamp(BsonTimestamp value)
Handles the logic of writing a timestampvoid
doWriteUndefined()
Handles the logic of writing an Undefined valuevoid
flush()
Flushes any pending data to the output destination.protected JsonWriter.Context
getContext()
Get the context, which will indicate which state the writer is in, for example which part of a document it's currently writing.Writer
getWriter()
Gets theWriter
.boolean
isTruncated()
Return true if the output has been truncated due to exceeding the length specified inJsonWriterSettings.getMaxLength()
.-
Methods inherited from class org.bson.AbstractBsonWriter
checkPreconditions, checkState, close, getName, getNextState, getState, isClosed, pipe, pipe, pipeExtraElements, setContext, setState, throwInvalidContextType, throwInvalidState, writeBinaryData, writeBinaryData, writeBoolean, writeBoolean, writeDateTime, writeDateTime, writeDBPointer, writeDBPointer, writeDecimal128, writeDecimal128, writeDouble, writeDouble, writeEndArray, writeEndDocument, writeInt32, writeInt32, writeInt64, writeInt64, writeJavaScript, writeJavaScript, writeJavaScriptWithScope, writeJavaScriptWithScope, writeMaxKey, writeMaxKey, writeMinKey, writeMinKey, writeName, writeNull, writeNull, writeObjectId, writeObjectId, writeRegularExpression, writeRegularExpression, writeStartArray, writeStartArray, writeStartDocument, writeStartDocument, writeString, writeString, writeSymbol, writeSymbol, writeTimestamp, writeTimestamp, writeUndefined, writeUndefined
-
-
-
-
Constructor Detail
-
JsonWriter
public JsonWriter(Writer writer)
Creates a new instance which useswriter
to write JSON to.- Parameters:
writer
- the writer to write JSON to.
-
JsonWriter
public JsonWriter(Writer writer, JsonWriterSettings settings)
Creates a new instance which useswriter
to write JSON to and uses the given settings.- Parameters:
writer
- the writer to write JSON to.settings
- the settings to apply to this writer.
-
-
Method Detail
-
getWriter
public Writer getWriter()
Gets theWriter
.- Returns:
- the writer
-
getContext
protected JsonWriter.Context getContext()
Description copied from class:AbstractBsonWriter
Get the context, which will indicate which state the writer is in, for example which part of a document it's currently writing.- Overrides:
getContext
in classAbstractBsonWriter
- Returns:
- the current context.
-
doWriteName
protected void doWriteName(String name)
Description copied from class:AbstractBsonWriter
Handles the logic of writing the element name.- Overrides:
doWriteName
in classAbstractBsonWriter
- Parameters:
name
- the name of the element
-
doWriteStartDocument
protected void doWriteStartDocument()
Description copied from class:AbstractBsonWriter
Handles the logic to start writing a document- Specified by:
doWriteStartDocument
in classAbstractBsonWriter
-
doWriteEndDocument
protected void doWriteEndDocument()
Description copied from class:AbstractBsonWriter
Handles the logic of writing the end of a document- Specified by:
doWriteEndDocument
in classAbstractBsonWriter
-
doWriteStartArray
protected void doWriteStartArray()
Description copied from class:AbstractBsonWriter
Handles the logic to start writing an array- Specified by:
doWriteStartArray
in classAbstractBsonWriter
-
doWriteEndArray
protected void doWriteEndArray()
Description copied from class:AbstractBsonWriter
Handles the logic of writing the end of an array- Specified by:
doWriteEndArray
in classAbstractBsonWriter
-
doWriteBinaryData
protected void doWriteBinaryData(BsonBinary binary)
Description copied from class:AbstractBsonWriter
Handles the logic of writing aBsonBinary
value- Specified by:
doWriteBinaryData
in classAbstractBsonWriter
- Parameters:
binary
- theBsonBinary
value to write
-
doWriteBoolean
public void doWriteBoolean(boolean value)
Description copied from class:AbstractBsonWriter
Handles the logic of writing a boolean value- Specified by:
doWriteBoolean
in classAbstractBsonWriter
- Parameters:
value
- theboolean
value to write
-
doWriteDateTime
protected void doWriteDateTime(long value)
Description copied from class:AbstractBsonWriter
Handles the logic of writing a date time value- Specified by:
doWriteDateTime
in classAbstractBsonWriter
- Parameters:
value
- thelong
value to write
-
doWriteDBPointer
protected void doWriteDBPointer(BsonDbPointer value)
Description copied from class:AbstractBsonWriter
Handles the logic of writing a DbPointer value- Specified by:
doWriteDBPointer
in classAbstractBsonWriter
- Parameters:
value
- theBsonDbPointer
value to write
-
doWriteDouble
protected void doWriteDouble(double value)
Description copied from class:AbstractBsonWriter
Handles the logic of writing a Double value- Specified by:
doWriteDouble
in classAbstractBsonWriter
- Parameters:
value
- thedouble
value to write
-
doWriteInt32
protected void doWriteInt32(int value)
Description copied from class:AbstractBsonWriter
Handles the logic of writing an int32 value- Specified by:
doWriteInt32
in classAbstractBsonWriter
- Parameters:
value
- theint
value to write
-
doWriteInt64
protected void doWriteInt64(long value)
Description copied from class:AbstractBsonWriter
Handles the logic of writing an int64 value- Specified by:
doWriteInt64
in classAbstractBsonWriter
- Parameters:
value
- thelong
value to write
-
doWriteDecimal128
protected void doWriteDecimal128(Decimal128 value)
Description copied from class:AbstractBsonWriter
Handles the logic of writing a Decimal128 value- Specified by:
doWriteDecimal128
in classAbstractBsonWriter
- Parameters:
value
- theDecimal128
value to write
-
doWriteJavaScript
protected void doWriteJavaScript(String code)
Description copied from class:AbstractBsonWriter
Handles the logic of writing a JavaScript function- Specified by:
doWriteJavaScript
in classAbstractBsonWriter
- Parameters:
code
- theString
value to write
-
doWriteJavaScriptWithScope
protected void doWriteJavaScriptWithScope(String code)
Description copied from class:AbstractBsonWriter
Handles the logic of writing a scoped JavaScript function- Specified by:
doWriteJavaScriptWithScope
in classAbstractBsonWriter
- Parameters:
code
- theboolean
value to write
-
doWriteMaxKey
protected void doWriteMaxKey()
Description copied from class:AbstractBsonWriter
Handles the logic of writing a Max key- Specified by:
doWriteMaxKey
in classAbstractBsonWriter
-
doWriteMinKey
protected void doWriteMinKey()
Description copied from class:AbstractBsonWriter
Handles the logic of writing a Min key- Specified by:
doWriteMinKey
in classAbstractBsonWriter
-
doWriteNull
public void doWriteNull()
Description copied from class:AbstractBsonWriter
Handles the logic of writing a Null value- Specified by:
doWriteNull
in classAbstractBsonWriter
-
doWriteObjectId
public void doWriteObjectId(ObjectId objectId)
Description copied from class:AbstractBsonWriter
Handles the logic of writing an ObjectId- Specified by:
doWriteObjectId
in classAbstractBsonWriter
- Parameters:
objectId
- theObjectId
value to write
-
doWriteRegularExpression
public void doWriteRegularExpression(BsonRegularExpression regularExpression)
Description copied from class:AbstractBsonWriter
Handles the logic of writing a regular expression- Specified by:
doWriteRegularExpression
in classAbstractBsonWriter
- Parameters:
regularExpression
- theBsonRegularExpression
value to write
-
doWriteString
public void doWriteString(String value)
Description copied from class:AbstractBsonWriter
Handles the logic of writing a String- Specified by:
doWriteString
in classAbstractBsonWriter
- Parameters:
value
- theString
value to write
-
doWriteSymbol
public void doWriteSymbol(String value)
Description copied from class:AbstractBsonWriter
Handles the logic of writing a Symbol- Specified by:
doWriteSymbol
in classAbstractBsonWriter
- Parameters:
value
- theboolean
value to write
-
doWriteTimestamp
public void doWriteTimestamp(BsonTimestamp value)
Description copied from class:AbstractBsonWriter
Handles the logic of writing a timestamp- Specified by:
doWriteTimestamp
in classAbstractBsonWriter
- Parameters:
value
- theBsonTimestamp
value to write
-
doWriteUndefined
public void doWriteUndefined()
Description copied from class:AbstractBsonWriter
Handles the logic of writing an Undefined value- Specified by:
doWriteUndefined
in classAbstractBsonWriter
-
flush
public void flush()
Description copied from interface:BsonWriter
Flushes any pending data to the output destination.
-
isTruncated
public boolean isTruncated()
Return true if the output has been truncated due to exceeding the length specified inJsonWriterSettings.getMaxLength()
.- Returns:
- true if the output has been truncated
- Since:
- 3.7
- See Also:
JsonWriterSettings.getMaxLength()
-
abortPipe
protected boolean abortPipe()
Description copied from class:AbstractBsonWriter
Return true if the current execution of the pipe method should be aborted.- Overrides:
abortPipe
in classAbstractBsonWriter
- Returns:
- true if the current execution of the pipe method should be aborted.
-
-