Package com.fasterxml.jackson.core.json
Class JsonWriteContext
- java.lang.Object
-
- com.fasterxml.jackson.core.JsonStreamContext
-
- com.fasterxml.jackson.core.json.JsonWriteContext
-
public class JsonWriteContext extends JsonStreamContext
Extension ofJsonStreamContext, which implements core methods needed, and also exposes more complete API to generator implementation classes.
-
-
Field Summary
Fields Modifier and Type Field Description static intSTATUS_EXPECT_NAMEstatic intSTATUS_EXPECT_VALUEstatic intSTATUS_OK_AFTER_COLONstatic intSTATUS_OK_AFTER_COMMAstatic intSTATUS_OK_AFTER_SPACEstatic intSTATUS_OK_AS_IS-
Fields inherited from class com.fasterxml.jackson.core.JsonStreamContext
TYPE_ARRAY, TYPE_OBJECT, TYPE_ROOT
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description JsonWriteContextclearAndGetParent()Method that can be used to both clear the accumulated references (specifically value set withsetCurrentValue(Object)) that should not be retained, and returns parent (as wouldgetParent()do).JsonWriteContextcreateChildArrayContext()JsonWriteContextcreateChildArrayContext(java.lang.Object currValue)JsonWriteContextcreateChildObjectContext()JsonWriteContextcreateChildObjectContext(java.lang.Object currValue)static JsonWriteContextcreateRootContext()Deprecated.Since 2.3; use method that takes argumentstatic JsonWriteContextcreateRootContext(DupDetector dd)java.lang.StringgetCurrentName()Method for accessing name associated with the current location.java.lang.ObjectgetCurrentValue()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.DupDetectorgetDupDetector()JsonWriteContextgetParent()Accessor for finding parent context of this context; will return null for root context.booleanhasCurrentName()JsonWriteContextreset(int type)Internal method to allow instance reuse: DO NOT USE unless you absolutely know what you are doing.JsonWriteContextreset(int type, java.lang.Object currValue)Internal method to allow instance reuse: DO NOT USE unless you absolutely know what you are doing.voidsetCurrentValue(java.lang.Object v)Method to call to pass value to be returned viaJsonStreamContext.getCurrentValue(); typically called indirectly throughJsonParser.setCurrentValue(java.lang.Object)orJsonGenerator.setCurrentValue(java.lang.Object)).JsonWriteContextwithDupDetector(DupDetector dups)intwriteFieldName(java.lang.String name)Method that writer is to call before it writes a name of Object property.intwriteValue()-
Methods inherited from class com.fasterxml.jackson.core.JsonStreamContext
getCurrentIndex, getEntryCount, getStartLocation, getTypeDesc, hasCurrentIndex, hasPathSegment, inArray, inObject, inRoot, pathAsPointer, pathAsPointer, startLocation, toString, typeDesc
-
-
-
-
Field Detail
-
STATUS_OK_AS_IS
public static final int STATUS_OK_AS_IS
- See Also:
- Constant Field Values
-
STATUS_OK_AFTER_COMMA
public static final int STATUS_OK_AFTER_COMMA
- See Also:
- Constant Field Values
-
STATUS_OK_AFTER_COLON
public static final int STATUS_OK_AFTER_COLON
- See Also:
- Constant Field Values
-
STATUS_OK_AFTER_SPACE
public static final int STATUS_OK_AFTER_SPACE
- See Also:
- Constant Field Values
-
STATUS_EXPECT_VALUE
public static final int STATUS_EXPECT_VALUE
- See Also:
- Constant Field Values
-
STATUS_EXPECT_NAME
public static final int STATUS_EXPECT_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
reset
public JsonWriteContext reset(int type)
Internal method to allow instance reuse: DO NOT USE unless you absolutely know what you are doing. Clears up state (including "current value"), changes type to one specified; resets current duplicate-detection state (if any). Parent link left as-is since it isfinal.NOTE: Public since 2.12.
- Parameters:
type- Type to assign to this context node- Returns:
- This context instance to allow call-chaining
-
reset
public JsonWriteContext reset(int type, java.lang.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 isfinal.NOTE: Public since 2.12.
- Parameters:
type- Type to assign to this context nodecurrValue- 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)
-
getCurrentValue
public java.lang.Object getCurrentValue()
Description copied from class:JsonStreamContextMethod 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:
getCurrentValuein classJsonStreamContext- Returns:
- Currently active value, if one has been assigned.
-
setCurrentValue
public void setCurrentValue(java.lang.Object v)
Description copied from class:JsonStreamContextMethod to call to pass value to be returned viaJsonStreamContext.getCurrentValue(); typically called indirectly throughJsonParser.setCurrentValue(java.lang.Object)orJsonGenerator.setCurrentValue(java.lang.Object)).- Overrides:
setCurrentValuein classJsonStreamContext- Parameters:
v- Current value to assign to this context
-
createRootContext
@Deprecated public static JsonWriteContext createRootContext()
Deprecated.Since 2.3; use method that takes argument- Returns:
- Context instance created
-
createRootContext
public static JsonWriteContext createRootContext(DupDetector dd)
-
createChildArrayContext
public JsonWriteContext createChildArrayContext()
-
createChildArrayContext
public JsonWriteContext createChildArrayContext(java.lang.Object currValue)
-
createChildObjectContext
public JsonWriteContext createChildObjectContext()
-
createChildObjectContext
public JsonWriteContext createChildObjectContext(java.lang.Object currValue)
-
getParent
public final JsonWriteContext getParent()
Description copied from class:JsonStreamContextAccessor for finding parent context of this context; will return null for root context.- Specified by:
getParentin classJsonStreamContext- Returns:
- Parent context of this context, if any;
nullfor Root contexts
-
getCurrentName
public final java.lang.String getCurrentName()
Description copied from class:JsonStreamContextMethod for accessing name associated with the current location. Non-null forFIELD_NAMEand value events that directly follow field names; null for root level and array values.- Specified by:
getCurrentNamein classJsonStreamContext- Returns:
- Current field name within context, if any;
nullif none
-
hasCurrentName
public boolean hasCurrentName()
- Overrides:
hasCurrentNamein classJsonStreamContext- Returns:
Trueif a call toJsonStreamContext.getCurrentName()would return non-nullname;falseotherwise
-
clearAndGetParent
public JsonWriteContext clearAndGetParent()
Method that can be used to both clear the accumulated references (specifically value set withsetCurrentValue(Object)) that should not be retained, and returns parent (as wouldgetParent()do). Typically called when closing the active context when encounteringJsonToken.END_ARRAYorJsonToken.END_OBJECT.- Returns:
- Parent context of this context node, if any;
nullfor root context - Since:
- 2.7
-
getDupDetector
public DupDetector getDupDetector()
-
writeFieldName
public int writeFieldName(java.lang.String name) throws JsonProcessingExceptionMethod that writer is to call before it writes a name of Object property.- Parameters:
name- Property name being written- Returns:
- Index of the field entry (0-based)
- Throws:
JsonProcessingException- if duplicate check restriction is violated
-
writeValue
public int writeValue()
-
-