java.lang.Object
tools.jackson.core.JsonGenerator
tools.jackson.core.base.GeneratorBase
tools.jackson.core.json.JsonGeneratorBase
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,Versioned
- Direct Known Subclasses:
UTF8JsonGenerator,WriterBasedJsonGenerator
Intermediate base class shared by JSON-backed generators
like
UTF8JsonGenerator and WriterBasedJsonGenerator.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanFlag set to indicate that implicit conversion from number to JSON String is needed (as perJsonWriteFeature.WRITE_NUMBERS_AS_STRINGS).protected final PrettyPrinterObject that handles pretty-printing (usually additional white space to make results more human-readable) during output.protected final booleanFlag that is set if quoting is not to be added around JSON Object property names.protected booleanWhether to write Hex values with upper-case letters (true) or lower-case (false)protected CharacterEscapesDefinition of custom character escapes to use for generators created by this factory, if any.protected final intBit flag composed of bits that indicate whichJsonWriteFeatures are enabled.protected final intValue between 128 (0x80) and 65535 (0xFFFF) that indicates highest Unicode code point that will not need escaping; or 0 to indicate that all characters can be represented without escaping.protected int[]Currently active set of output escape code definitions (whether and how to escape or not) for 7-bit ASCII range (first 128 character codes).protected final SerializableStringSeparator to use, if any, between root-level values.protected JsonWriteContextObject that keeps track of the current contextual state of the generator.protected static final int[]This is the default set of escape codes, over 7-bit ASCII range (first 128 character codes), used for single-byte UTF-8 characters.Fields inherited from class tools.jackson.core.base.GeneratorBase
_closed, _ioContext, _objectWriteContext, _streamWriteConstraints, _streamWriteFeatures, DEFAULT_BINARY_WRITE_CAPABILITIES, DEFAULT_TEXTUAL_WRITE_CAPABILITIES, DEFAULT_WRITE_CAPABILITIES, MAX_BIG_DECIMAL_SCALE, SURR1_FIRST, SURR1_LAST, SURR2_FIRST, SURR2_LAST, WRITE_BINARY, WRITE_BOOLEAN, WRITE_NULL, WRITE_NUMBER, WRITE_RAW, WRITE_STRING -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedJsonGeneratorBase(ObjectWriteContext writeCtxt, IOContext ioCtxt, int streamWriteFeatures, int formatWriteFeatures, SerializableString rootValueSeparator, PrettyPrinter pp, CharacterEscapes charEsc, int maxNonEscaped) -
Method Summary
Modifier and TypeMethodDescriptionprotected void_reportCantWriteValueExpectName(String typeMsg) protected void_verifyPrettyValueWrite(String typeMsg, int status) final voidHelper method, usually equivalent to:getOutputContext().assignCurrentValue(v);used to assign "current value" for the current context of this generator.final ObjectHelper method, usually equivalent to:getOutputContext().currentValue();Method for accessing custom escapes factory uses forJsonGenerators it creates.intAccessor method for testing what is the highest unescaped character configured for this generator.booleanabstract JsonGeneratorMethod for defining custom escapes factory uses forJsonGenerators it creates.Accessor for getting metadata on capabilities of this generator, based on underlying data format being read (directly or indirectly).final TokenStreamContextAccessor for context object that provides information about low-level logical position withing output token stream.version()Accessor for finding out version of the bundle that provided this generator instance.writePropertyId(long id) Alternative toJsonGenerator.writeName(String)that may be used in cases where Object Property key is of numeric type; usually where underlying format supports such notion (some binary formats do, unlike JSON).writeStartArray(Object currentValue, 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 currentValue, int size) Method for writing starting marker of an Object value to represent the given Java Object value.Methods inherited from class tools.jackson.core.base.GeneratorBase
_asString, _checkRangeBoundsForByteArray, _checkRangeBoundsForCharArray, _checkRangeBoundsForString, _closeInput, _constructDefaultPrettyPrinter, _decodeSurrogate, _releaseBuffers, _throwInternal, _verifyValueWrite, close, configure, ioContext, isClosed, isEnabled, objectWriteContext, streamWriteConstraints, streamWriteFeatures, writeBinary, writeName, writePOJO, writeRawValue, writeRawValue, writeRawValue, writeRawValue, writeString, writeString, writeTreeMethods inherited from class tools.jackson.core.JsonGenerator
_constructWriteException, _constructWriteException, _constructWriteException, _constructWriteException, _copyCurrentContents, _copyCurrentFloatValue, _copyCurrentFloatValueExact, _copyCurrentIntValue, _copyCurrentStringValue, _reportArgumentError, _reportError, _reportUnsupportedOperation, _reportUnsupportedOperation, _verifyOffsets, _wrapIOFailure, _writeTypePrefixUsingNative, _writeTypePrefixUsingWrapper, canOmitProperties, canWriteObjectId, canWriteTypeId, copyCurrentEvent, copyCurrentEventExact, copyCurrentStructure, flush, getSchema, streamWriteOutputBuffered, streamWriteOutputTarget, 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, writeRaw, writeRaw, writeRaw, writeRaw, writeRaw, writeRawUTF8String, writeStartArray, writeStartArray, writeStartObject, writeStartObject, writeString, writeString, writeStringProperty, writeTypeId, writeTypePrefix, writeTypeSuffix, writeUTF8String
-
Field Details
-
DEFAULT_OUTPUT_ESCAPES
protected static final int[] DEFAULT_OUTPUT_ESCAPESThis is the default set of escape codes, over 7-bit ASCII range (first 128 character codes), used for single-byte UTF-8 characters. -
_formatWriteFeatures
protected final int _formatWriteFeaturesBit flag composed of bits that indicate whichJsonWriteFeatures are enabled. -
_outputEscapes
protected int[] _outputEscapesCurrently active set of output escape code definitions (whether and how to escape or not) for 7-bit ASCII range (first 128 character codes). Defined separately to make potentially customizable -
_characterEscapes
Definition of custom character escapes to use for generators created by this factory, if any. If null, standard data format specific escapes are used.NOTE: although typically set during construction (in constructor), cannot be made final in 3.0 due to some edge use cases (JSONP support).
-
_maximumNonEscapedChar
protected final int _maximumNonEscapedCharValue between 128 (0x80) and 65535 (0xFFFF) that indicates highest Unicode code point that will not need escaping; or 0 to indicate that all characters can be represented without escaping. Typically used to force escaping of some portion of character set; for example to always escape non-ASCII characters (if value was 127).NOTE: not all sub-classes make use of this setting.
-
_cfgPrettyPrinter
Object that handles pretty-printing (usually additional white space to make results more human-readable) during output. If null, no pretty-printing is done. -
_rootValueSeparator
Separator to use, if any, between root-level values. -
_cfgUnqNames
protected final boolean _cfgUnqNamesFlag that is set if quoting is not to be added around JSON Object property names. -
_cfgNumbersAsStrings
protected final boolean _cfgNumbersAsStringsFlag set to indicate that implicit conversion from number to JSON String is needed (as perJsonWriteFeature.WRITE_NUMBERS_AS_STRINGS). -
_cfgWriteHexUppercase
protected boolean _cfgWriteHexUppercaseWhether to write Hex values with upper-case letters (true) or lower-case (false) -
_streamWriteContext
Object that keeps track of the current contextual state of the generator.
-
-
Constructor Details
-
JsonGeneratorBase
protected JsonGeneratorBase(ObjectWriteContext writeCtxt, IOContext ioCtxt, int streamWriteFeatures, int formatWriteFeatures, SerializableString rootValueSeparator, PrettyPrinter pp, CharacterEscapes charEsc, int maxNonEscaped)
-
-
Method Details
-
version
Description copied from class:JsonGeneratorAccessor for finding out version of the bundle that provided this generator instance.- Specified by:
versionin interfaceVersioned- Specified by:
versionin classJsonGenerator- Returns:
- Version of the component
-
isEnabled
-
streamWriteCapabilities
Description copied from class:JsonGeneratorAccessor for getting metadata on capabilities of this generator, based on underlying data format being read (directly or indirectly).- Specified by:
streamWriteCapabilitiesin classJsonGenerator- Returns:
- Set of read capabilities for content to generate via this generator
-
getHighestNonEscapedChar
public int getHighestNonEscapedChar()Description copied from class:JsonGeneratorAccessor method for testing what is the highest unescaped character configured for this generator. This may be either positive value (when escaping configuration has been set and is in effect), or 0 to indicate that no additional escaping is in effect. Some generators may not support additional escaping: for example, generators for binary formats that do not use escaping should simply return 0.- Overrides:
getHighestNonEscapedCharin classJsonGenerator- Returns:
- Currently active limitation for highest non-escaped character, if defined; or 0 to indicate no additional escaping is performed.
-
setCharacterEscapes
Description copied from class:JsonGeneratorMethod for defining custom escapes factory uses forJsonGenerators it creates.Default implementation does nothing and simply returns this instance.
- Overrides:
setCharacterEscapesin classJsonGenerator- Parameters:
esc-CharacterEscapesto configure this generator to use, if any;nullif none- Returns:
- This generator, to allow call chaining
-
getCharacterEscapes
Method for accessing custom escapes factory uses forJsonGenerators it creates.- Overrides:
getCharacterEscapesin classJsonGenerator- Returns:
CharacterEscapesthis generator is configured to use, if any;nullif none
-
streamWriteContext
Description copied from class:JsonGeneratorAccessor for context object that provides information about low-level logical position withing output token stream.NOTE: method was called
getOutputContext()in Jackson 2.x- Specified by:
streamWriteContextin classJsonGenerator- Returns:
- Stream output context (
TokenStreamContext) associated with this generator
-
currentValue
Description copied from class:JsonGeneratorHelper method, usually equivalent to:getOutputContext().currentValue();Note that "current value" is NOT populated (or used) by Streaming generator; it is only used by higher-level data-binding functionality. The reason it is included here is that it can be stored and accessed hierarchically, and gets passed through data-binding.
- Specified by:
currentValuein classJsonGenerator- Returns:
- "Current value" for the current context this generator has
-
assignCurrentValue
Description copied from class:JsonGeneratorHelper method, usually equivalent to:getOutputContext().assignCurrentValue(v);used to assign "current value" for the current context of this generator. It is usually assigned and used by higher level data-binding functionality (instead of streaming parsers/generators) but is stored at streaming level.- Specified by:
assignCurrentValuein classJsonGenerator- Parameters:
v- "Current value" to assign to the current output context of 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().- Overrides:
writeStartArrayin classGeneratorBase- Parameters:
currentValue- 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.
- Overrides:
writeStartObjectin classGeneratorBase- Parameters:
currentValue- 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
-
writePropertyId
Description copied from class:JsonGeneratorAlternative toJsonGenerator.writeName(String)that may be used in cases where Object Property key is of numeric type; usually where underlying format supports such notion (some binary formats do, unlike JSON). Default implementation will simply convert id intoStringand callJsonGenerator.writeName(String).- Specified by:
writePropertyIdin classJsonGenerator- Parameters:
id- Property key id 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
-
_verifyPrettyValueWrite
- Throws:
JacksonException
-
_reportCantWriteValueExpectName
- Throws:
JacksonException
-