Package org.bson.json
Class JsonWriter
java.lang.Object
org.bson.AbstractBsonWriter
org.bson.json.JsonWriter
- All Implemented Interfaces:
Closeable,AutoCloseable,BsonWriter
A
BsonWriter implementation that outputs a JSON representation of BSON.- Since:
- 3.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassThe 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
ConstructorsConstructorDescriptionJsonWriter(Writer writer) Creates a new instance which useswriterto write JSON to.JsonWriter(Writer writer, JsonWriterSettings settings) Creates a new instance which useswriterto write JSON to and uses the given settings. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanReturn true if the current execution of the pipe method should be aborted.protected voiddoWriteBinaryData(BsonBinary binary) Handles the logic of writing aBsonBinaryvaluevoiddoWriteBoolean(boolean value) Handles the logic of writing a boolean valueprotected voiddoWriteDateTime(long value) Handles the logic of writing a date time valueprotected voiddoWriteDBPointer(BsonDbPointer value) Handles the logic of writing a DbPointer valueprotected voiddoWriteDecimal128(Decimal128 value) Handles the logic of writing a Decimal128 valueprotected voiddoWriteDouble(double value) Handles the logic of writing a Double valueprotected voidHandles the logic of writing the end of an arrayprotected voidHandles the logic of writing the end of a documentprotected voiddoWriteInt32(int value) Handles the logic of writing an int32 valueprotected voiddoWriteInt64(long value) Handles the logic of writing an int64 valueprotected voiddoWriteJavaScript(String code) Handles the logic of writing a JavaScript functionprotected voidHandles the logic of writing a scoped JavaScript functionprotected voidHandles the logic of writing a Max keyprotected voidHandles the logic of writing a Min keyprotected voiddoWriteName(String name) Handles the logic of writing the element name.voidHandles the logic of writing a Null valuevoiddoWriteObjectId(ObjectId objectId) Handles the logic of writing an ObjectIdvoiddoWriteRegularExpression(BsonRegularExpression regularExpression) Handles the logic of writing a regular expressionprotected voidHandles the logic to start writing an arrayprotected voidHandles the logic to start writing a documentvoiddoWriteString(String value) Handles the logic of writing a StringvoiddoWriteSymbol(String value) Handles the logic of writing a SymbolvoiddoWriteTimestamp(BsonTimestamp value) Handles the logic of writing a timestampvoidHandles the logic of writing an Undefined valuevoidflush()Flushes any pending data to the output destination.protected JsonWriter.ContextGet the context, which will indicate which state the writer is in, for example which part of a document it's currently writing.Gets theWriter.booleanReturn 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 Details
-
JsonWriter
Creates a new instance which useswriterto write JSON to.- Parameters:
writer- the writer to write JSON to.
-
JsonWriter
Creates a new instance which useswriterto 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 Details
-
getWriter
Gets theWriter.- Returns:
- the writer
-
getContext
Description copied from class:AbstractBsonWriterGet the context, which will indicate which state the writer is in, for example which part of a document it's currently writing.- Overrides:
getContextin classAbstractBsonWriter- Returns:
- the current context.
-
doWriteName
Description copied from class:AbstractBsonWriterHandles the logic of writing the element name.- Overrides:
doWriteNamein classAbstractBsonWriter- Parameters:
name- the name of the element
-
doWriteStartDocument
protected void doWriteStartDocument()Description copied from class:AbstractBsonWriterHandles the logic to start writing a document- Specified by:
doWriteStartDocumentin classAbstractBsonWriter
-
doWriteEndDocument
protected void doWriteEndDocument()Description copied from class:AbstractBsonWriterHandles the logic of writing the end of a document- Specified by:
doWriteEndDocumentin classAbstractBsonWriter
-
doWriteStartArray
protected void doWriteStartArray()Description copied from class:AbstractBsonWriterHandles the logic to start writing an array- Specified by:
doWriteStartArrayin classAbstractBsonWriter
-
doWriteEndArray
protected void doWriteEndArray()Description copied from class:AbstractBsonWriterHandles the logic of writing the end of an array- Specified by:
doWriteEndArrayin classAbstractBsonWriter
-
doWriteBinaryData
Description copied from class:AbstractBsonWriterHandles the logic of writing aBsonBinaryvalue- Specified by:
doWriteBinaryDatain classAbstractBsonWriter- Parameters:
binary- theBsonBinaryvalue to write
-
doWriteBoolean
public void doWriteBoolean(boolean value) Description copied from class:AbstractBsonWriterHandles the logic of writing a boolean value- Specified by:
doWriteBooleanin classAbstractBsonWriter- Parameters:
value- thebooleanvalue to write
-
doWriteDateTime
protected void doWriteDateTime(long value) Description copied from class:AbstractBsonWriterHandles the logic of writing a date time value- Specified by:
doWriteDateTimein classAbstractBsonWriter- Parameters:
value- thelongvalue to write
-
doWriteDBPointer
Description copied from class:AbstractBsonWriterHandles the logic of writing a DbPointer value- Specified by:
doWriteDBPointerin classAbstractBsonWriter- Parameters:
value- theBsonDbPointervalue to write
-
doWriteDouble
protected void doWriteDouble(double value) Description copied from class:AbstractBsonWriterHandles the logic of writing a Double value- Specified by:
doWriteDoublein classAbstractBsonWriter- Parameters:
value- thedoublevalue to write
-
doWriteInt32
protected void doWriteInt32(int value) Description copied from class:AbstractBsonWriterHandles the logic of writing an int32 value- Specified by:
doWriteInt32in classAbstractBsonWriter- Parameters:
value- theintvalue to write
-
doWriteInt64
protected void doWriteInt64(long value) Description copied from class:AbstractBsonWriterHandles the logic of writing an int64 value- Specified by:
doWriteInt64in classAbstractBsonWriter- Parameters:
value- thelongvalue to write
-
doWriteDecimal128
Description copied from class:AbstractBsonWriterHandles the logic of writing a Decimal128 value- Specified by:
doWriteDecimal128in classAbstractBsonWriter- Parameters:
value- theDecimal128value to write
-
doWriteJavaScript
Description copied from class:AbstractBsonWriterHandles the logic of writing a JavaScript function- Specified by:
doWriteJavaScriptin classAbstractBsonWriter- Parameters:
code- theStringvalue to write
-
doWriteJavaScriptWithScope
Description copied from class:AbstractBsonWriterHandles the logic of writing a scoped JavaScript function- Specified by:
doWriteJavaScriptWithScopein classAbstractBsonWriter- Parameters:
code- thebooleanvalue to write
-
doWriteMaxKey
protected void doWriteMaxKey()Description copied from class:AbstractBsonWriterHandles the logic of writing a Max key- Specified by:
doWriteMaxKeyin classAbstractBsonWriter
-
doWriteMinKey
protected void doWriteMinKey()Description copied from class:AbstractBsonWriterHandles the logic of writing a Min key- Specified by:
doWriteMinKeyin classAbstractBsonWriter
-
doWriteNull
public void doWriteNull()Description copied from class:AbstractBsonWriterHandles the logic of writing a Null value- Specified by:
doWriteNullin classAbstractBsonWriter
-
doWriteObjectId
Description copied from class:AbstractBsonWriterHandles the logic of writing an ObjectId- Specified by:
doWriteObjectIdin classAbstractBsonWriter- Parameters:
objectId- theObjectIdvalue to write
-
doWriteRegularExpression
Description copied from class:AbstractBsonWriterHandles the logic of writing a regular expression- Specified by:
doWriteRegularExpressionin classAbstractBsonWriter- Parameters:
regularExpression- theBsonRegularExpressionvalue to write
-
doWriteString
Description copied from class:AbstractBsonWriterHandles the logic of writing a String- Specified by:
doWriteStringin classAbstractBsonWriter- Parameters:
value- theStringvalue to write
-
doWriteSymbol
Description copied from class:AbstractBsonWriterHandles the logic of writing a Symbol- Specified by:
doWriteSymbolin classAbstractBsonWriter- Parameters:
value- thebooleanvalue to write
-
doWriteTimestamp
Description copied from class:AbstractBsonWriterHandles the logic of writing a timestamp- Specified by:
doWriteTimestampin classAbstractBsonWriter- Parameters:
value- theBsonTimestampvalue to write
-
doWriteUndefined
public void doWriteUndefined()Description copied from class:AbstractBsonWriterHandles the logic of writing an Undefined value- Specified by:
doWriteUndefinedin classAbstractBsonWriter
-
flush
public void flush()Description copied from interface:BsonWriterFlushes 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:
-
abortPipe
protected boolean abortPipe()Description copied from class:AbstractBsonWriterReturn true if the current execution of the pipe method should be aborted.- Overrides:
abortPipein classAbstractBsonWriter- Returns:
- true if the current execution of the pipe method should be aborted.
-