Class JsonGeneratorBase

All Implemented Interfaces:
Closeable, Flushable, AutoCloseable, Versioned
Direct Known Subclasses:
UTF8JsonGenerator, WriterBasedJsonGenerator

public abstract class JsonGeneratorBase extends GeneratorBase
Intermediate base class shared by JSON-backed generators like UTF8JsonGenerator and WriterBasedJsonGenerator.
  • Field Details

    • DEFAULT_OUTPUT_ESCAPES

      protected static final int[] DEFAULT_OUTPUT_ESCAPES
      This 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 _formatWriteFeatures
      Bit flag composed of bits that indicate which JsonWriteFeatures are enabled.
    • _outputEscapes

      protected int[] _outputEscapes
      Currently 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

      protected CharacterEscapes _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 _maximumNonEscapedChar
      Value 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

      protected final PrettyPrinter _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

      protected final SerializableString _rootValueSeparator
      Separator to use, if any, between root-level values.
    • _cfgUnqNames

      protected final boolean _cfgUnqNames
      Flag that is set if quoting is not to be added around JSON Object property names.
    • _cfgNumbersAsStrings

      protected final boolean _cfgNumbersAsStrings
      Flag set to indicate that implicit conversion from number to JSON String is needed (as per JsonWriteFeature.WRITE_NUMBERS_AS_STRINGS).
    • _cfgWriteHexUppercase

      protected boolean _cfgWriteHexUppercase
      Whether to write Hex values with upper-case letters (true) or lower-case (false)
    • _streamWriteContext

      protected JsonWriteContext _streamWriteContext
      Object that keeps track of the current contextual state of the generator.
  • Constructor Details

  • Method Details

    • version

      public Version version()
      Description copied from class: JsonGenerator
      Accessor for finding out version of the bundle that provided this generator instance.
      Specified by:
      version in interface Versioned
      Specified by:
      version in class JsonGenerator
      Returns:
      Version of the component
    • isEnabled

      public boolean isEnabled(JsonWriteFeature f)
    • streamWriteCapabilities

      public JacksonFeatureSet<StreamWriteCapability> streamWriteCapabilities()
      Description copied from class: JsonGenerator
      Accessor for getting metadata on capabilities of this generator, based on underlying data format being read (directly or indirectly).
      Specified by:
      streamWriteCapabilities in class JsonGenerator
      Returns:
      Set of read capabilities for content to generate via this generator
    • getHighestNonEscapedChar

      public int getHighestNonEscapedChar()
      Description copied from class: JsonGenerator
      Accessor 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:
      getHighestNonEscapedChar in class JsonGenerator
      Returns:
      Currently active limitation for highest non-escaped character, if defined; or 0 to indicate no additional escaping is performed.
    • setCharacterEscapes

      public abstract JsonGenerator setCharacterEscapes(CharacterEscapes esc)
      Description copied from class: JsonGenerator
      Method for defining custom escapes factory uses for JsonGenerators it creates.

      Default implementation does nothing and simply returns this instance.

      Overrides:
      setCharacterEscapes in class JsonGenerator
      Parameters:
      esc - CharacterEscapes to configure this generator to use, if any; null if none
      Returns:
      This generator, to allow call chaining
    • getCharacterEscapes

      public CharacterEscapes getCharacterEscapes()
      Method for accessing custom escapes factory uses for JsonGenerators it creates.
      Overrides:
      getCharacterEscapes in class JsonGenerator
      Returns:
      CharacterEscapes this generator is configured to use, if any; null if none
    • streamWriteContext

      public final TokenStreamContext streamWriteContext()
      Description copied from class: JsonGenerator
      Accessor 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:
      streamWriteContext in class JsonGenerator
      Returns:
      Stream output context (TokenStreamContext) associated with this generator
    • currentValue

      public final Object currentValue()
      Description copied from class: JsonGenerator
      Helper 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:
      currentValue in class JsonGenerator
      Returns:
      "Current value" for the current context this generator has
    • assignCurrentValue

      public final void assignCurrentValue(Object v)
      Description copied from class: JsonGenerator
      Helper 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:
      assignCurrentValue in class JsonGenerator
      Parameters:
      v - "Current value" to assign to the current output context of this generator
    • writeStartArray

      public JsonGenerator writeStartArray(Object currentValue, int size) throws JacksonException
      Description copied from class: JsonGenerator
      Method for writing start marker of an Array value, similar to JsonGenerator.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 JsonGenerator.writeEndArray().
      Overrides:
      writeStartArray in class GeneratorBase
      Parameters:
      currentValue - Java Object that Array being written represents, if any (or null if not known or not applicable)
      size - Number of elements this Array will have: actual number of values written (before matching call to JsonGenerator.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 problem
      StreamWriteException - for problems in encoding token stream
      JacksonException
    • writeStartObject

      public JsonGenerator writeStartObject(Object currentValue, int size) throws JacksonException
      Description copied from class: JsonGenerator
      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.

      Overrides:
      writeStartObject in class GeneratorBase
      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 to JsonGenerator.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 problem
      StreamWriteException - for problems in encoding token stream
      JacksonException
    • writePropertyId

      public JsonGenerator writePropertyId(long id) throws JacksonException
      Description copied from class: JsonGenerator
      Alternative to JsonGenerator.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 into String and call JsonGenerator.writeName(String).
      Specified by:
      writePropertyId in class JsonGenerator
      Parameters:
      id - Property key id to write
      Returns:
      This generator, to allow call chaining
      Throws:
      JacksonIOException - if there is an underlying I/O problem
      StreamWriteException - for problems in encoding token stream
      JacksonException
    • _verifyPrettyValueWrite

      protected void _verifyPrettyValueWrite(String typeMsg, int status) throws JacksonException
      Throws:
      JacksonException
    • _reportCantWriteValueExpectName

      protected void _reportCantWriteValueExpectName(String typeMsg) throws JacksonException
      Throws:
      JacksonException