Top Description Fields Constructors Methods
tools.jackson.core.base

public abstract Class GeneratorBase

extends JsonGenerator
Class Inheritance
Known Direct Subclasses
tools.jackson.core.json.JsonGeneratorBase
Imports
java.io.IOException, .InputStream, .Reader, java.math.BigDecimal, tools.jackson.core.*, tools.jackson.core.io.IOContext, .UTF8Writer, tools.jackson.core.util.DefaultPrettyPrinter, .JacksonFeatureSet, .VersionUtil

This base class implements part of API that a JSON generator exposes to applications, adds shared internal methods that sub-classes can use and adds some abstract methods sub-classes must implement.

Field Summary

Modifier and TypeField and Description
protected boolean
_closed

Flag that indicates whether generator is closed or not.

protected final IOContext
_ioContext

Low-level I/O context used mostly for buffer recycling.

protected final ObjectWriteContext
_objectWriteContext

Context object used both to pass some initial settings and to allow triggering of Object serialization through generator.

protected final StreamWriteConstraints
_streamWriteConstraints

Constraints to use for this generator.

protected int
_streamWriteFeatures

Bit flag composed of bits that indicate which tools.jackson.core.StreamWriteFeatures are enabled.

protected static final JacksonFeatureSet<StreamWriteCapability>
DEFAULT_BINARY_WRITE_CAPABILITIES

Default set of StreamWriteCapabilityies for typical binary formats, to use either as-is, or as a base with possible differences.

protected static final JacksonFeatureSet<StreamWriteCapability>
DEFAULT_TEXTUAL_WRITE_CAPABILITIES

Default set of StreamWriteCapabilityies for typical textual formats, to use either as-is, or as a base with possible differences.

protected static final JacksonFeatureSet<StreamWriteCapability>
DEFAULT_WRITE_CAPABILITIES

Default set of StreamWriteCapabilityies 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 int
MAX_BIG_DECIMAL_SCALE

This value is the limit of scale allowed for serializing java.math.BigDecimal in "plain" (non-engineering) notation; intent is to prevent asymmetric attack whereupon simple eng-notation with big scale is used to generate huge "plain" serialization.

public static final int
public static final int
public static final int
public static final int
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String

Constructor Summary

AccessConstructor and Description
protected
GeneratorBase(ObjectWriteContext writeCtxt, IOContext ioCtxt, int streamWriteFeatures)

Method Summary

Modifier and TypeMethod and Description
protected String

Returns:

String representation of value
_asString
(BigDecimal
BigDecimal value to convert to String
value
)

Helper method used to serialize a java.math.BigDecimal as a String, for serialization, taking into account configuration settings

protected 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 void
protected PrettyPrinter

Returns:

Instance of "default" pretty printer to use
_constructDefaultPrettyPrinter
()

Overridable factory method called to instantiate an appropriate PrettyPrinter for case of "just use the default one", when default pretty printer handling enabled.

protected final int
_decodeSurrogate(int surr1, int surr2)

protected abstract void
_releaseBuffers()

Method called to release any buffers generator may be holding, once generator is being closed.

protected void
protected abstract void
_verifyValueWrite(String
Additional message used for generating exception message if value output is NOT legal in current generator output state.
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.

public void
close()

Implements abstract tools.jackson.core.JsonGenerator.close.

Implements java.io.Closeable.close.

Method called to close this generator, so that no more content can be written.

public final JsonGenerator
configure(StreamWriteFeature f, boolean state)

Implements abstract tools.jackson.core.JsonGenerator.configure.

Method for enabling or disabling specified feature: check StreamWriteFeature for list of available features.

public boolean
has(StreamWriteCapability capability)

Implements abstract tools.jackson.core.JsonGenerator.has.

Accessor for checking whether this generator has specified capability.

public IOContext

Returns:

IOContext in use by this generator
ioContext
()

Accessor for use by jackson-core itself (tests in particular).

public boolean
isClosed()

Implements abstract tools.jackson.core.JsonGenerator.isClosed.

Method that can be called to determine whether this generator is closed or not.

public final boolean
isEnabled(StreamWriteFeature f)

Implements abstract tools.jackson.core.JsonGenerator.isEnabled.

Method for checking whether given feature is enabled.

public ObjectWriteContext
objectWriteContext()

Implements abstract tools.jackson.core.JsonGenerator.objectWriteContext.

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.

public final StreamWriteConstraints
streamWriteConstraints()

Overrides tools.jackson.core.JsonGenerator.streamWriteConstraints.

Get the constraints to apply when performing streaming writes.

public final int
streamWriteFeatures()

Implements abstract tools.jackson.core.JsonGenerator.streamWriteFeatures.

Bulk access method for getting state of all standard (format-agnostic) StreamWriteFeatures.

public int
writeBinary(Base64Variant b64variant, InputStream data, int dataLength)

Implements abstract tools.jackson.core.JsonGenerator.writeBinary.

Method similar to writeBinary(Base64Variant, byte[], int, int), but where input is provided through a stream, allowing for incremental writes without holding the whole input in memory.

public JsonGenerator
writeName(SerializableString name)

Implements abstract tools.jackson.core.JsonGenerator.writeName.

Method similar to 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.

public JsonGenerator
writePOJO(Object value)

Implements abstract tools.jackson.core.JsonGenerator.writePOJO.

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).

public JsonGenerator
writeRawValue(String text)

Implements abstract tools.jackson.core.JsonGenerator.writeRawValue.

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).

public JsonGenerator
writeRawValue(String text, int offset, int len)

Implements abstract tools.jackson.core.JsonGenerator.writeRawValue.

public JsonGenerator
writeRawValue(char[] text, int offset, int len)

Implements abstract tools.jackson.core.JsonGenerator.writeRawValue.

public JsonGenerator
writeRawValue(SerializableString text)

Overrides tools.jackson.core.JsonGenerator.writeRawValue.

Method similar to writeRawValue(String), but potentially more efficient as it may be able to use pre-encoded content (similar to writeRaw(SerializableString).

public JsonGenerator
writeStartArray(Object forValue, int size)

Implements abstract tools.jackson.core.JsonGenerator.writeStartArray.

Method for writing start marker of an Array value, similar to 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 calling writeEndArray().

public JsonGenerator
writeStartObject(Object forValue, int size)

Implements abstract tools.jackson.core.JsonGenerator.writeStartObject.

Method for writing starting marker of an Object value to represent the given Java Object value.

public JsonGenerator
writeString(Reader reader, int len)

Implements abstract tools.jackson.core.JsonGenerator.writeString.

Method for outputting a String value.

public JsonGenerator
writeString(SerializableString text)

Implements abstract tools.jackson.core.JsonGenerator.writeString.

Method similar to writeString(String), but that takes SerializableString which can make this potentially more efficient to call as generator may be able to reuse quoted and/or encoded representation.

public JsonGenerator
writeTree(TreeNode rootNode)

Implements abstract tools.jackson.core.JsonGenerator.writeTree.

Method for writing given JSON tree (expressed as a tree where given TreeNode is the root) using this generator.

Inherited from tools.jackson.core.JsonGenerator:
_constructWriteException_constructWriteException_constructWriteException_constructWriteException_copyCurrentContents_copyCurrentContentsExact_copyCurrentFloatValue_copyCurrentFloatValueExact_copyCurrentIntValue_copyCurrentStringValue_reportArgumentError_reportError_reportUnsupportedOperation_reportUnsupportedOperation_verifyOffsets_wrapIOFailure_writeTypePrefixUsingNative_writeTypePrefixUsingWrapperassignCurrentValuecanOmitPropertiescanWriteObjectIdcanWriteTypeIdcopyCurrentEventcopyCurrentEventExactcopyCurrentStructurecopyCurrentStructureExactcurrentValueflushgetCharacterEscapesgetHighestNonEscapedChargetPrettyPrintergetSchemasetCharacterEscapesstreamWriteCapabilitiesstreamWriteContextstreamWriteOutputBufferedstreamWriteOutputTargetversionwriteArraywriteArraywriteArraywriteArraywriteArrayPropertyStartwriteBinarywriteBinarywriteBinarywriteBinarywriteBinaryPropertywriteBooleanwriteBooleanPropertywriteEmbeddedObjectwriteEndArraywriteEndObjectwriteNamewriteNullwriteNullPropertywriteNumberwriteNumberwriteNumberwriteNumberwriteNumberwriteNumberwriteNumberwriteNumberwriteNumberwriteNumberPropertywriteNumberPropertywriteNumberPropertywriteNumberPropertywriteNumberPropertywriteNumberPropertywriteNumberPropertywriteObjectIdwriteObjectPropertyStartwriteObjectRefwriteOmittedPropertywritePOJOPropertywritePropertyIdwriteRawwriteRawwriteRawwriteRawwriteRawwriteRawUTF8StringwriteStartArraywriteStartArraywriteStartObjectwriteStartObjectwriteStringwriteStringwriteStringPropertywriteTypeIdwriteTypePrefixwriteTypeSuffixwriteUTF8String

Field Detail

_closedback to summary
protected boolean _closed

Flag that indicates whether generator is closed or not. Gets set when it is closed by an explicit call (close).

_ioContextback to summary
protected final IOContext _ioContext

Low-level I/O context used mostly for buffer recycling.

_objectWriteContextback to summary
protected final ObjectWriteContext _objectWriteContext

Context object used both to pass some initial settings and to allow triggering of Object serialization through generator.

Since
3.0
_streamWriteConstraintsback to summary
protected final StreamWriteConstraints _streamWriteConstraints

Constraints to use for this generator.

_streamWriteFeaturesback to summary
protected int _streamWriteFeatures

Bit flag composed of bits that indicate which tools.jackson.core.StreamWriteFeatures are enabled.

DEFAULT_BINARY_WRITE_CAPABILITIESback to summary
protected static final JacksonFeatureSet<StreamWriteCapability> DEFAULT_BINARY_WRITE_CAPABILITIES

Default set of StreamWriteCapabilityies for typical binary formats, to use either as-is, or as a base with possible differences.

DEFAULT_TEXTUAL_WRITE_CAPABILITIESback to summary
protected static final JacksonFeatureSet<StreamWriteCapability> DEFAULT_TEXTUAL_WRITE_CAPABILITIES

Default set of StreamWriteCapabilityies for typical textual formats, to use either as-is, or as a base with possible differences.

DEFAULT_WRITE_CAPABILITIESback to summary
protected static final JacksonFeatureSet<StreamWriteCapability> DEFAULT_WRITE_CAPABILITIES

Default set of StreamWriteCapabilityies that may be used as basis for format-specific readers (or as bogus instance if non-null set needs to be passed).

MAX_BIG_DECIMAL_SCALEback to summary
protected static final int MAX_BIG_DECIMAL_SCALE

This value is the limit of scale allowed for serializing java.math.BigDecimal in "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.

SURR1_FIRSTback to summary
public static final int SURR1_FIRST
SURR1_LASTback to summary
public static final int SURR1_LAST
SURR2_FIRSTback to summary
public static final int SURR2_FIRST
SURR2_LASTback to summary
public static final int SURR2_LAST
WRITE_BINARYback to summary
protected static final String WRITE_BINARY
WRITE_BOOLEANback to summary
protected static final String WRITE_BOOLEAN
WRITE_NULLback to summary
protected static final String WRITE_NULL
WRITE_NUMBERback to summary
protected static final String WRITE_NUMBER
WRITE_RAWback to summary
protected static final String WRITE_RAW
WRITE_STRINGback to summary
protected static final String WRITE_STRING

Constructor Detail

GeneratorBaseback to summary
protected GeneratorBase(ObjectWriteContext writeCtxt, IOContext ioCtxt, int streamWriteFeatures)

Method Detail

_asStringback to summary
protected String _asString(BigDecimal value) throws JacksonException

Helper method used to serialize a java.math.BigDecimal as a String, for serialization, taking into account configuration settings

Parameters
value:BigDecimal

BigDecimal value to convert to String

Returns:String

String representation of value

Exceptions
JacksonException:
if there is a problem serializing value as String
_checkRangeBoundsForByteArrayback to summary
protected void _checkRangeBoundsForByteArray(byte[] data, int offset, int len) throws JacksonException
_checkRangeBoundsForCharArrayback to summary
protected void _checkRangeBoundsForCharArray(char[] data, int offset, int len) throws JacksonException
_checkRangeBoundsForStringback to summary
protected void _checkRangeBoundsForString(String data, int offset, int len) throws JacksonException
_closeInputback to summary
protected abstract void _closeInput() throws IOException
_constructDefaultPrettyPrinterback to summary
protected PrettyPrinter _constructDefaultPrettyPrinter()

Overridable factory method called to instantiate an appropriate PrettyPrinter for case of "just use the default one", when default pretty printer handling enabled.

Returns:PrettyPrinter

Instance of "default" pretty printer to use

_decodeSurrogateback to summary
protected final int _decodeSurrogate(int surr1, int surr2) throws JacksonException
_releaseBuffersback to summary
protected abstract void _releaseBuffers()

Method called to release any buffers generator may be holding, once generator is being closed.

_throwInternalback to summary
protected void _throwInternal()
_verifyValueWriteback to summary
protected abstract void _verifyValueWrite(String typeMsg) throws JacksonException

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:String

Additional message used for generating exception message if value output is NOT legal in current generator output state.

Exceptions
JacksonException:
if there is a problem in trying to write a value
closeback to summary
public void close()

Implements abstract tools.jackson.core.JsonGenerator.close.

Implements java.io.Closeable.close.

Doc from tools.jackson.core.JsonGenerator.close.

Method 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_TARGET enabled. If either of above is true, the target is also closed. Otherwise (not managing, feature not enabled), target is not closed.

Annotations
@Override
configureback to summary
public final JsonGenerator configure(StreamWriteFeature f, boolean state)

Implements abstract tools.jackson.core.JsonGenerator.configure.

Doc from tools.jackson.core.JsonGenerator.configure.

Method for enabling or disabling specified feature: check StreamWriteFeature for list of available features.

Note

mostly left in 3.0 just to support disabling of StreamWriteFeature#AUTO_CLOSE_CONTENT by jackson-databind

Annotations
@Override
hasback to summary
public boolean has(StreamWriteCapability capability)

Implements abstract tools.jackson.core.JsonGenerator.has.

Doc from tools.jackson.core.JsonGenerator.has.

Accessor for checking whether this generator has specified capability. Short-hand for: return getWriteCapabilities().isEnabled(capability);

Annotations
@Override
ioContextback to summary
public IOContext ioContext()

Accessor for use by jackson-core itself (tests in particular).

Returns:IOContext

IOContext in use by this generator

isClosedback to summary
public boolean isClosed()

Implements abstract tools.jackson.core.JsonGenerator.isClosed.

Doc from tools.jackson.core.JsonGenerator.isClosed.

Method that can be called to determine whether this generator is closed or not. If it is closed, no more output can be done.

Annotations
@Override
isEnabledback to summary
public final boolean isEnabled(StreamWriteFeature f)

Implements abstract tools.jackson.core.JsonGenerator.isEnabled.

Doc from tools.jackson.core.JsonGenerator.isEnabled.

Method for checking whether given feature is enabled. Check StreamWriteFeature for list of available features.

Annotations
@Override
objectWriteContextback to summary
public ObjectWriteContext objectWriteContext()

Implements abstract tools.jackson.core.JsonGenerator.objectWriteContext.

Doc from tools.jackson.core.JsonGenerator.objectWriteContext.

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.

Annotations
@Override
streamWriteConstraintsback to summary
public final StreamWriteConstraints streamWriteConstraints()

Overrides tools.jackson.core.JsonGenerator.streamWriteConstraints.

Doc from tools.jackson.core.JsonGenerator.streamWriteConstraints.

Get the constraints to apply when performing streaming writes.

Annotations
@Override
streamWriteFeaturesback to summary
public final int streamWriteFeatures()

Implements abstract tools.jackson.core.JsonGenerator.streamWriteFeatures.

Doc from tools.jackson.core.JsonGenerator.streamWriteFeatures.

Bulk access method for getting state of all standard (format-agnostic) StreamWriteFeatures.

Annotations
@Override
writeBinaryback to summary
public int writeBinary(Base64Variant b64variant, InputStream data, int dataLength) throws JacksonException

Implements abstract tools.jackson.core.JsonGenerator.writeBinary.

Doc from tools.jackson.core.JsonGenerator.writeBinary.

Method similar to writeBinary(Base64Variant, byte[], int, int), but where input is provided through a stream, allowing for incremental writes without holding the whole input in memory.

Annotations
@Override
writeNameback to summary
public JsonGenerator writeName(SerializableString name) throws JacksonException

Implements abstract tools.jackson.core.JsonGenerator.writeName.

Doc from tools.jackson.core.JsonGenerator.writeName.

Method similar to 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.

Annotations
@Override
writePOJOback to summary
public JsonGenerator writePOJO(Object value) throws JacksonException

Implements abstract tools.jackson.core.JsonGenerator.writePOJO.

Doc from tools.jackson.core.JsonGenerator.writePOJO.

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). This is done by delegating call to ObjectWriteContext#writeValue(JsonGenerator, Object).

Annotations
@Override
writeRawValueback to summary
public JsonGenerator writeRawValue(String text) throws JacksonException

Implements abstract tools.jackson.core.JsonGenerator.writeRawValue.

Doc from tools.jackson.core.JsonGenerator.writeRawValue.

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). Assuming this, proper separators are added if and as needed (comma or colon), and generator state updated to reflect this.

Annotations
@Override
writeRawValueback to summary
public JsonGenerator writeRawValue(String text, int offset, int len) throws JacksonException

Implements abstract tools.jackson.core.JsonGenerator.writeRawValue.

Annotations
@Override
writeRawValueback to summary
public JsonGenerator writeRawValue(char[] text, int offset, int len) throws JacksonException

Implements abstract tools.jackson.core.JsonGenerator.writeRawValue.

Annotations
@Override
writeRawValueback to summary
public JsonGenerator writeRawValue(SerializableString text) throws JacksonException

Overrides tools.jackson.core.JsonGenerator.writeRawValue.

Doc from tools.jackson.core.JsonGenerator.writeRawValue.

Method similar to writeRawValue(String), but potentially more efficient as it may be able to use pre-encoded content (similar to writeRaw(SerializableString).

Annotations
@Override
writeStartArrayback to summary
public JsonGenerator writeStartArray(Object forValue, int size) throws JacksonException

Implements abstract tools.jackson.core.JsonGenerator.writeStartArray.

Doc from tools.jackson.core.JsonGenerator.writeStartArray.

Method for writing start marker of an Array value, similar to 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 calling writeEndArray().

Annotations
@Override
writeStartObjectback to summary
public JsonGenerator writeStartObject(Object forValue, int size) throws JacksonException

Implements abstract tools.jackson.core.JsonGenerator.writeStartObject.

Doc from tools.jackson.core.JsonGenerator.writeStartObject.

Method 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.

Annotations
@Override
writeStringback to summary
public JsonGenerator writeString(Reader reader, int len) throws JacksonException

Implements abstract tools.jackson.core.JsonGenerator.writeString.

Doc from tools.jackson.core.JsonGenerator.writeString.

Method 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. If len is < 0, then write all contents of the reader. Otherwise, write only len characters.

Note

actual length of content available may exceed len but cannot be less than it: if not enough content available, a StreamWriteException will be thrown.

Annotations
@Override
writeStringback to summary
public JsonGenerator writeString(SerializableString text) throws JacksonException

Implements abstract tools.jackson.core.JsonGenerator.writeString.

Doc from tools.jackson.core.JsonGenerator.writeString.

Method similar to writeString(String), but that takes SerializableString which can make this potentially more efficient to call as generator may be able to reuse quoted and/or encoded representation.

Default implementation just calls writeString(String); sub-classes should override it with more efficient implementation if possible.

Annotations
@Override
writeTreeback to summary
public JsonGenerator writeTree(TreeNode rootNode) throws JacksonException

Implements abstract tools.jackson.core.JsonGenerator.writeTree.

Doc from tools.jackson.core.JsonGenerator.writeTree.

Method for writing given JSON tree (expressed as a tree where given TreeNode is the root) using this generator. This is done by delegating call to ObjectWriteContext#writeTree.

Annotations
@Override