- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,Versioned
- Direct Known Subclasses:
JsonGeneratorBase
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanFlag that indicates whether generator is closed or not.protected final IOContextLow-level I/O context used mostly for buffer recycling.protected final ObjectWriteContextContext object used both to pass some initial settings and to allow triggering of Object serialization through generator.protected final StreamWriteConstraintsConstraints to use for this generator.protected intBit flag composed of bits that indicate whichStreamWriteFeatures are enabled.protected static final JacksonFeatureSet<StreamWriteCapability>Default set ofStreamWriteCapabilityies for typical binary formats, to use either as-is, or as a base with possible differences.protected static final JacksonFeatureSet<StreamWriteCapability>Default set ofStreamWriteCapabilityies for typical textual formats, to use either as-is, or as a base with possible differences.protected static final JacksonFeatureSet<StreamWriteCapability>Default set ofStreamWriteCapabilityies that may be used as basis for format-specific readers (or as bogus instance if non-null set needs to be passed).protected static final intThis value is the limit of scale allowed for serializingBigDecimalin "plain" (non-engineering) notation; intent is to prevent asymmetric attack whereupon simple eng-notation with big scale is used to generate huge "plain" serialization.static final intstatic final intstatic final intstatic final intprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final String -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedGeneratorBase(ObjectWriteContext writeCtxt, IOContext ioCtxt, int streamWriteFeatures) -
Method Summary
Modifier and TypeMethodDescriptionprotected String_asString(BigDecimal value) Helper method used to serialize aBigDecimalas a String, for serialization, taking into account configuration settingsprotected void_checkRangeBoundsForByteArray(byte[] data, int offset, int len) protected void_checkRangeBoundsForCharArray(char[] data, int offset, int len) protected void_checkRangeBoundsForString(String data, int offset, int len) protected abstract voidprotected PrettyPrinterOverridable factory method called to instantiate an appropriatePrettyPrinterfor case of "just use the default one", when default pretty printer handling enabled.protected final int_decodeSurrogate(int surr1, int surr2) protected abstract voidMethod called to release any buffers generator may be holding, once generator is being closed.protected voidprotected abstract void_verifyValueWrite(String typeMsg) Method called before trying to write a value (scalar or structured), to verify that this is legal in current output state, as well as to output separators if and as necessary.voidclose()Method called to close this generator, so that no more content can be written.final JsonGeneratorconfigure(StreamWriteFeature f, boolean state) Method for enabling or disabling specified feature: checkStreamWriteFeaturefor list of available features.Accessor for use byjackson-coreitself (tests in particular).booleanisClosed()Method that can be called to determine whether this generator is closed or not.final booleanMethod for checking whether given feature is enabled.Accessor for context object provided by higher-level databinding functionality (or, in some cases, simple placeholder of the same) that allows some level of interaction including ability to trigger serialization of Object values through generator instance.final StreamWriteConstraintsGet the constraints to apply when performing streaming writes.final intBulk access method for getting state of all standard (format-agnostic)StreamWriteFeatures.intwriteBinary(Base64Variant b64variant, InputStream data, int dataLength) Method similar toJsonGenerator.writeBinary(Base64Variant,byte[],int,int), but where input is provided through a stream, allowing for incremental writes without holding the whole input in memory.writeName(SerializableString name) Method similar toJsonGenerator.writeName(String), main difference being that it may perform better as some of processing (such as quoting of certain characters, or encoding into external encoding if supported by generator) can be done just once and reused for later calls.Method for writing given Java object (POJO) as tokens into stream this generator manages; serialization must be a valid JSON Value (Object, Array, null, Number, String or Boolean).writeRawValue(char[] text, int offset, int len) writeRawValue(String text) Method that will force generator to copy input text verbatim without any modifications, but assuming it must constitute a single legal JSON value (number, string, boolean, null, Array or List).writeRawValue(String text, int offset, int len) Method similar toJsonGenerator.writeRawValue(String), but potentially more efficient as it may be able to use pre-encoded content (similar toJsonGenerator.writeRaw(SerializableString).writeStartArray(Object forValue, int size) Method for writing start marker of an Array value, similar toJsonGenerator.writeStartArray(), but also specifying what is the Java object that the Array Object being written represents (if any) and how many elements will be written for the array before callingJsonGenerator.writeEndArray().writeStartObject(Object forValue, int size) Method for writing starting marker of an Object value to represent the given Java Object value.writeString(Reader reader, int len) Method for outputting a String value.Method similar toJsonGenerator.writeString(String), but that takesSerializableStringwhich can make this potentially more efficient to call as generator may be able to reuse quoted and/or encoded representation.Method for writing given JSON tree (expressed as a tree where givenTreeNodeis the root) using this generator.Methods inherited from class tools.jackson.core.JsonGenerator
_constructWriteException, _constructWriteException, _constructWriteException, _constructWriteException, _copyCurrentContents, _copyCurrentFloatValue, _copyCurrentFloatValueExact, _copyCurrentIntValue, _copyCurrentStringValue, _reportArgumentError, _reportError, _reportUnsupportedOperation, _reportUnsupportedOperation, _verifyOffsets, _wrapIOFailure, _writeTypePrefixUsingNative, _writeTypePrefixUsingWrapper, assignCurrentValue, canOmitProperties, canWriteObjectId, canWriteTypeId, copyCurrentEvent, copyCurrentEventExact, copyCurrentStructure, currentValue, flush, getCharacterEscapes, getHighestNonEscapedChar, getSchema, setCharacterEscapes, streamWriteCapabilities, streamWriteContext, streamWriteOutputBuffered, streamWriteOutputTarget, version, writeArray, writeArray, writeArray, writeArray, writeArrayPropertyStart, writeBinary, writeBinary, writeBinary, writeBinary, writeBinaryProperty, writeBoolean, writeBooleanProperty, writeEmbeddedObject, writeEndArray, writeEndObject, writeName, writeNull, writeNullProperty, writeNumber, writeNumber, writeNumber, writeNumber, writeNumber, writeNumber, writeNumber, writeNumber, writeNumber, writeNumberProperty, writeNumberProperty, writeNumberProperty, writeNumberProperty, writeNumberProperty, writeNumberProperty, writeNumberProperty, writeObjectId, writeObjectPropertyStart, writeObjectRef, writeOmittedProperty, writePOJOProperty, writePropertyId, writeRaw, writeRaw, writeRaw, writeRaw, writeRaw, writeRawUTF8String, writeStartArray, writeStartArray, writeStartObject, writeStartObject, writeString, writeString, writeStringProperty, writeTypeId, writeTypePrefix, writeTypeSuffix, writeUTF8String
-
Field Details
-
SURR1_FIRST
public static final int SURR1_FIRST- See Also:
-
SURR1_LAST
public static final int SURR1_LAST- See Also:
-
SURR2_FIRST
public static final int SURR2_FIRST- See Also:
-
SURR2_LAST
public static final int SURR2_LAST- See Also:
-
WRITE_BINARY
- See Also:
-
WRITE_BOOLEAN
- See Also:
-
WRITE_NULL
- See Also:
-
WRITE_NUMBER
- See Also:
-
WRITE_RAW
- See Also:
-
WRITE_STRING
- See Also:
-
MAX_BIG_DECIMAL_SCALE
protected static final int MAX_BIG_DECIMAL_SCALEThis value is the limit of scale allowed for serializingBigDecimalin "plain" (non-engineering) notation; intent is to prevent asymmetric attack whereupon simple eng-notation with big scale is used to generate huge "plain" serialization. See [core#315] for details.- See Also:
-
DEFAULT_WRITE_CAPABILITIES
Default set ofStreamWriteCapabilityies that may be used as basis for format-specific readers (or as bogus instance if non-null set needs to be passed). -
DEFAULT_TEXTUAL_WRITE_CAPABILITIES
Default set ofStreamWriteCapabilityies for typical textual formats, to use either as-is, or as a base with possible differences. -
DEFAULT_BINARY_WRITE_CAPABILITIES
Default set ofStreamWriteCapabilityies for typical binary formats, to use either as-is, or as a base with possible differences. -
_objectWriteContext
Context object used both to pass some initial settings and to allow triggering of Object serialization through generator.- Since:
- 3.0
-
_ioContext
Low-level I/O context used mostly for buffer recycling. -
_streamWriteConstraints
Constraints to use for this generator. -
_streamWriteFeatures
protected int _streamWriteFeaturesBit flag composed of bits that indicate whichStreamWriteFeatures are enabled. -
_closed
protected boolean _closedFlag that indicates whether generator is closed or not. Gets set when it is closed by an explicit call (close()).
-
-
Constructor Details
-
GeneratorBase
-
-
Method Details
-
isEnabled
Description copied from class:JsonGeneratorMethod for checking whether given feature is enabled. CheckStreamWriteFeaturefor list of available features.- Specified by:
isEnabledin classJsonGenerator- Parameters:
f- Feature to check- Returns:
Trueif feature is enabled;falseif not
-
streamWriteFeatures
public final int streamWriteFeatures()Description copied from class:JsonGeneratorBulk access method for getting state of all standard (format-agnostic)StreamWriteFeatures.- Specified by:
streamWriteFeaturesin classJsonGenerator- Returns:
- Bit mask that defines current states of all standard
StreamWriteFeatures.
-
configure
Description copied from class:JsonGeneratorMethod for enabling or disabling specified feature: checkStreamWriteFeaturefor list of available features.NOTE: mostly left in 3.0 just to support disabling of
StreamWriteFeature.AUTO_CLOSE_CONTENTbyjackson-databind- Specified by:
configurein classJsonGenerator- Parameters:
f- Feature to enable or disablestate- Whether to enable the feature (true) or disable (false)- Returns:
- This generator, to allow call chaining
-
streamWriteConstraints
Description copied from class:JsonGeneratorGet the constraints to apply when performing streaming writes.- Overrides:
streamWriteConstraintsin classJsonGenerator- Returns:
- Constraints used for this generator
-
objectWriteContext
Description copied from class:JsonGeneratorAccessor for context object provided by higher-level databinding functionality (or, in some cases, simple placeholder of the same) that allows some level of interaction including ability to trigger serialization of Object values through generator instance.- Specified by:
objectWriteContextin classJsonGenerator- Returns:
- Object write context (
ObjectWriteContext) associated with this generator
-
ioContext
Accessor for use byjackson-coreitself (tests in particular).- Returns:
IOContextin use by this generator
-
writeStartArray
Description copied from class:JsonGeneratorMethod for writing start marker of an Array value, similar toJsonGenerator.writeStartArray(), but also specifying what is the Java object that the Array Object being written represents (if any) and how many elements will be written for the array before callingJsonGenerator.writeEndArray().- Specified by:
writeStartArrayin classJsonGenerator- Parameters:
forValue- Java Object that Array being written represents, if any (ornullif not known or not applicable)size- Number of elements this Array will have: actual number of values written (before matching call toJsonGenerator.writeEndArray()MUST match; generator MAY verify this is the case (and SHOULD if format itself encodes length)- Returns:
- This generator, to allow call chaining
- Throws:
JacksonIOException- if there is an underlying I/O problemStreamWriteException- for problems in encoding token streamJacksonException
-
writeStartObject
Description copied from class:JsonGeneratorMethod for writing starting marker of an Object value to represent the given Java Object value. Argument is offered as metadata, but more importantly it should be assigned as the "current value" for the Object content that gets constructed and initialized. In addition, caller knows number of key/value pairs ("properties") that will get written for the Object value: this is relevant for some format backends (but not, as an example, for JSON).Object values can be written in any context where values are allowed: meaning everywhere except for when a property name is expected.
- Specified by:
writeStartObjectin classJsonGenerator- Parameters:
forValue- Object value to be written (assigned as "current value" for the Object context that gets created)size- Number of key/value pairs this Object will have: actual number of entries written (before matching call toJsonGenerator.writeEndObject()MUST match; generator MAY verify this is the case (and SHOULD if format itself encodes length)- Returns:
- This generator, to allow call chaining
- Throws:
JacksonIOException- if there is an underlying I/O problemStreamWriteException- for problems in encoding token streamJacksonException
-
writeName
Description copied from class:JsonGeneratorMethod similar toJsonGenerator.writeName(String), main difference being that it may perform better as some of processing (such as quoting of certain characters, or encoding into external encoding if supported by generator) can be done just once and reused for later calls.Default implementation simple uses unprocessed name container in serialized String; implementations are strongly encouraged to make use of more efficient methods argument object has.
- Specified by:
writeNamein classJsonGenerator- Parameters:
name- Pre-encoded name of the Object Property to write- Returns:
- This generator, to allow call chaining
- Throws:
JacksonIOException- if there is an underlying I/O problemStreamWriteException- for problems in encoding token streamJacksonException
-
writeString
Description copied from class:JsonGeneratorMethod for outputting a String value. Depending on context this means either array element, (object) property value or a stand alone String; but in all cases, String will be surrounded in double quotes, and contents will be properly escaped as required by JSON specification. Iflenis < 0, then write all contents of the reader. Otherwise, write only len characters.Note: actual length of content available may exceed
lenbut cannot be less than it: if not enough content available, aStreamWriteExceptionwill be thrown.- Specified by:
writeStringin classJsonGenerator- Parameters:
reader- Reader to use for reading Text value to writelen- Maximum Length of Text value to read (inchars, non-negative) if known;-1to indicate "read and write it all"- Returns:
- This generator, to allow call chaining
- Throws:
JacksonIOException- if there is an underlying I/O problemStreamWriteException- for problems in encoding token stream (including the case wherereaderdoes not provide enough content)JacksonException
-
writeString
Description copied from class:JsonGeneratorMethod similar toJsonGenerator.writeString(String), but that takesSerializableStringwhich can make this potentially more efficient to call as generator may be able to reuse quoted and/or encoded representation.Default implementation just calls
JsonGenerator.writeString(String); sub-classes should override it with more efficient implementation if possible.- Specified by:
writeStringin classJsonGenerator- Parameters:
text- Pre-encoded String value to write- Returns:
- This generator, to allow call chaining
- Throws:
JacksonIOException- if there is an underlying I/O problemStreamWriteException- for problems in encoding token streamJacksonException
-
writeRawValue
Description copied from class:JsonGeneratorMethod that will force generator to copy input text verbatim without any modifications, but assuming it must constitute a single legal JSON value (number, string, boolean, null, Array or List). Assuming this, proper separators are added if and as needed (comma or colon), and generator state updated to reflect this.- Specified by:
writeRawValuein classJsonGenerator- Parameters:
text- Textual contents to included in output- Returns:
- This generator, to allow call chaining
- Throws:
JacksonIOException- if there is an underlying I/O problemStreamWriteException- for problems in encoding token streamJacksonException
-
writeRawValue
- Specified by:
writeRawValuein classJsonGenerator- Throws:
JacksonException
-
writeRawValue
- Specified by:
writeRawValuein classJsonGenerator- Throws:
JacksonException
-
writeRawValue
Description copied from class:JsonGeneratorMethod similar toJsonGenerator.writeRawValue(String), but potentially more efficient as it may be able to use pre-encoded content (similar toJsonGenerator.writeRaw(SerializableString).- Overrides:
writeRawValuein classJsonGenerator- Parameters:
text- Pre-encoded textual contents to included in output- Returns:
- This generator, to allow call chaining
- Throws:
JacksonIOException- if there is an underlying I/O problemStreamWriteException- for problems in encoding token streamJacksonException
-
writeBinary
public int writeBinary(Base64Variant b64variant, InputStream data, int dataLength) throws JacksonException Description copied from class:JsonGeneratorMethod similar toJsonGenerator.writeBinary(Base64Variant,byte[],int,int), but where input is provided through a stream, allowing for incremental writes without holding the whole input in memory.- Specified by:
writeBinaryin classJsonGenerator- Parameters:
b64variant- Base64 variant to usedata- InputStream to use for reading binary data to write. Will not be closed after successful write operationdataLength- (optional) number of bytes that will be available; or -1 to be indicate it is not known. If a positive length is given,dataMUST provide at least that many bytes: if not, an exception will be thrown. Note that implementations need not support cases where length is not known in advance; this depends on underlying data format: JSON output does NOT require length, other formats may.- Returns:
- Number of bytes read from
dataand written as binary payload - Throws:
JacksonIOException- if there is an underlying I/O problemStreamWriteException- for problems in encoding token streamJacksonException
-
writePOJO
Description copied from class:JsonGeneratorMethod for writing given Java object (POJO) as tokens into stream this generator manages; serialization must be a valid JSON Value (Object, Array, null, Number, String or Boolean). This is done by delegating call toObjectWriteContext.writeValue(JsonGenerator, Object).- Specified by:
writePOJOin classJsonGenerator- Parameters:
value- Java Object (POJO) value to write- Returns:
- This generator, to allow call chaining
- Throws:
JacksonIOException- if there is an underlying I/O problemStreamWriteException- for problems in encoding token streamJacksonException
-
writeTree
Description copied from class:JsonGeneratorMethod for writing given JSON tree (expressed as a tree where givenTreeNodeis the root) using this generator. This is done by delegating call toObjectWriteContext.writeTree(tools.jackson.core.JsonGenerator, tools.jackson.core.TreeNode).- Specified by:
writeTreein classJsonGenerator- Parameters:
rootNode-TreeNodeto write- Returns:
- This generator, to allow call chaining
- Throws:
JacksonIOException- if there is an underlying I/O problemStreamWriteException- for problems in encoding token streamJacksonException
-
isClosed
public boolean isClosed()Description copied from class:JsonGeneratorMethod that can be called to determine whether this generator is closed or not. If it is closed, no more output can be done.- Specified by:
isClosedin classJsonGenerator- Returns:
Trueif this generator has been closed;falseif not
-
close
public void close()Description copied from class:JsonGeneratorMethod called to close this generator, so that no more content can be written.Whether the underlying target (stream, writer) gets closed depends on whether this generator either manages the target (i.e. is the only one with access to the target -- case if caller passes a reference to the resource such as File, but not stream); or has feature
StreamWriteFeature.AUTO_CLOSE_TARGETenabled. If either of above is true, the target is also closed. Otherwise (not managing, feature not enabled), target is not closed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classJsonGenerator
-
_closeInput
- Throws:
IOException
-
_releaseBuffers
protected abstract void _releaseBuffers()Method called to release any buffers generator may be holding, once generator is being closed. -
_verifyValueWrite
Method called before trying to write a value (scalar or structured), to verify that this is legal in current output state, as well as to output separators if and as necessary.- Parameters:
typeMsg- Additional message used for generating exception message if value output is NOT legal in current generator output state.- Throws:
JacksonException- if there is a problem in trying to write a value
-
_constructDefaultPrettyPrinter
Overridable factory method called to instantiate an appropriatePrettyPrinterfor case of "just use the default one", when default pretty printer handling enabled.- Returns:
- Instance of "default" pretty printer to use
-
_asString
Helper method used to serialize aBigDecimalas a String, for serialization, taking into account configuration settings- Parameters:
value- BigDecimal value to convert to String- Returns:
- String representation of
value - Throws:
JacksonException- if there is a problem serializing value as String
-
_decodeSurrogate
- Throws:
JacksonException
-
_checkRangeBoundsForByteArray
protected void _checkRangeBoundsForByteArray(byte[] data, int offset, int len) throws JacksonException - Throws:
JacksonException
-
_checkRangeBoundsForCharArray
protected void _checkRangeBoundsForCharArray(char[] data, int offset, int len) throws JacksonException - Throws:
JacksonException
-
_checkRangeBoundsForString
- Throws:
JacksonException
-
_throwInternal
protected void _throwInternal()
-