Class JsonWriteContext

java.lang.Object
tools.jackson.core.TokenStreamContext
tools.jackson.core.json.JsonWriteContext

public class JsonWriteContext extends TokenStreamContext
Extension of TokenStreamContext, which implements core methods needed, and also exposes more complete API to generator implementation classes.
  • Field Details

    • STATUS_OK_AS_IS

      public static final int STATUS_OK_AS_IS
      See Also:
    • STATUS_OK_AFTER_COMMA

      public static final int STATUS_OK_AFTER_COMMA
      See Also:
    • STATUS_OK_AFTER_COLON

      public static final int STATUS_OK_AFTER_COLON
      See Also:
    • STATUS_OK_AFTER_SPACE

      public static final int STATUS_OK_AFTER_SPACE
      See Also:
    • STATUS_EXPECT_VALUE

      public static final int STATUS_EXPECT_VALUE
      See Also:
    • STATUS_EXPECT_NAME

      public static final int STATUS_EXPECT_NAME
      See Also:
    • _parent

      protected final JsonWriteContext _parent
      Parent context for this context; null for root context.
    • _dups

      protected DupDetector _dups
    • _child

      protected JsonWriteContext _child
    • _currentName

      protected String _currentName
      Name of the Object property of which value is to be written; only used for OBJECT contexts
    • _currentValue

      protected Object _currentValue
    • _gotName

      protected boolean _gotName
      Marker used to indicate that we just wrote a name, and now expect a value to write
  • Constructor Details

  • Method Details

    • reset

      protected JsonWriteContext reset(int type, Object currValue)
      Internal method to allow instance reuse: DO NOT USE unless you absolutely know what you are doing. Clears up state, changes type to one specified, assigns "current value"; resets current duplicate-detection state (if any). Parent link left as-is since it is final.
      Parameters:
      type - Type to assign to this context node
      currValue - Current value to assign to this context node
      Returns:
      This context instance to allow call-chaining
      Since:
      2.10
    • withDupDetector

      public JsonWriteContext withDupDetector(DupDetector dups)
    • currentValue

      public Object currentValue()
      Description copied from class: TokenStreamContext
      Method for accessing currently active value being used by data-binding (as the source of streaming data to write, or destination of data being read), at this level in hierarchy.

      Note that "current value" is NOT populated (or used) by Streaming parser or 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.

      Overrides:
      currentValue in class TokenStreamContext
      Returns:
      Currently active value, if one has been assigned.
    • assignCurrentValue

      public void assignCurrentValue(Object v)
      Description copied from class: TokenStreamContext
      Method to call to pass value to be returned via TokenStreamContext.currentValue(); typically called indirectly through JsonParser.assignCurrentValue(java.lang.Object) or JsonGenerator.assignCurrentValue(java.lang.Object)).
      Overrides:
      assignCurrentValue in class TokenStreamContext
      Parameters:
      v - Current value to assign to this context
    • createRootContext

      public static JsonWriteContext createRootContext(DupDetector dd)
    • createChildArrayContext

      public JsonWriteContext createChildArrayContext(Object currValue)
    • createChildObjectContext

      public JsonWriteContext createChildObjectContext(Object currValue)
    • getParent

      public final JsonWriteContext getParent()
      Description copied from class: TokenStreamContext
      Accessor for finding parent context of this context; will return null for root context.
      Specified by:
      getParent in class TokenStreamContext
      Returns:
      Parent context of this context, if any; null for Root contexts
    • currentName

      public final String currentName()
      Description copied from class: TokenStreamContext
      Method for accessing name associated with the current location. Non-null for PROPERTY_NAME and value events that directly follow Property names; null for root level and array values.
      Specified by:
      currentName in class TokenStreamContext
      Returns:
      Current property name within context, if any; null if none
    • hasCurrentName

      public boolean hasCurrentName()
      Overrides:
      hasCurrentName in class TokenStreamContext
    • clearAndGetParent

      public JsonWriteContext clearAndGetParent()
      Method that can be used to both clear the accumulated references (specifically value set with assignCurrentValue(Object)) that should not be retained, and returns parent (as would getParent() do). Typically called when closing the active context when encountering JsonToken.END_ARRAY or JsonToken.END_OBJECT.
      Returns:
      Parent context of this context node, if any; null for root context
    • getDupDetector

      public DupDetector getDupDetector()
    • writeName

      public int writeName(String name) throws StreamWriteException
      Method that generator is to call when it writes a name of Object property.
      Parameters:
      name - Property name being written
      Returns:
      Index of the Object property (0-based)
      Throws:
      StreamWriteException - if duplicate check restriction is violated (which assumes that duplicate-detection is enabled)
    • writeValue

      public int writeValue()