Top Description Inners Fields Constructors Methods
com.fasterxml.jackson.databind.deser.std

public Class JsonNodeDeserializer

Additional top-level class in compilation unit: BaseNodeDeserializer.

extends BaseNodeDeserializer<JsonNode>
Class Inheritance
Annotations
@SuppressWarnings:serial
Imports
java.io.IOException, java.math.BigDecimal, java.util.Arrays, com.fasterxml.jackson.core.*, com.fasterxml.jackson.databind.*, com.fasterxml.jackson.databind.cfg.DatatypeFeatures, .JsonNodeFeature, com.fasterxml.jackson.databind.deser.ContextualDeserializer, com.fasterxml.jackson.databind.jsontype.TypeDeserializer, com.fasterxml.jackson.databind.node.*, com.fasterxml.jackson.databind.type.LogicalType, com.fasterxml.jackson.databind.util.RawValue

Deserializer that can build instances of JsonNode from any JSON content, using appropriate JsonNode type.

Rewritten in Jackson 2.13 to avoid recursion and allow handling of very deeply nested structures.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
JsonNodeDeserializer.ArrayDeserializer

Implementation used when declared type is specifically ArrayNode.

pack-priv static class
JsonNodeDeserializer.ObjectDeserializer

Implementation used when declared type is specifically ObjectNode.

Field Summary

Modifier and TypeField and Description
private static final JsonNodeDeserializer
instance

Singleton instance of generic deserializer for JsonNode.

Inherited from com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer:
_mergeArrays_mergeObjects_supportsUpdates

Constructor Summary

AccessConstructor and Description
protected
protected
JsonNodeDeserializer(JsonNodeDeserializer base, boolean mergeArrays, boolean mergeObjects)

Method Summary

Modifier and TypeMethod and Description
protected JsonDeserializer<?>
_createWithMerge(boolean mergeArrays, boolean mergeObjects)

Implements abstract com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer._createWithMerge.

public JsonNode
deserialize(JsonParser
Parser used for reading JSON content
p
,
DeserializationContext
Context that can be used to access information about this deserialization activity.
ctxt
)

Implements abstract com.fasterxml.jackson.databind.JsonDeserializer.deserialize.

Implementation that will produce types of any JSON nodes; not just one deserializer is registered to handle (in case of more specialized handler).

public Object
getAbsentValue(DeserializationContext ctxt)

Overrides com.fasterxml.jackson.databind.JsonDeserializer.getAbsentValue.

Overrides default com.fasterxml.jackson.databind.deser.NullValueProvider.getAbsentValue.

Overridden variant to ensure that absent values are NOT coerced into NullNodes, unlike incoming null values.

public static JsonDeserializer<? extends JsonNode>
getDeserializer(Class<?> nodeClass)

Factory method for accessing deserializer for specific node type

public JsonNode
getNullValue(DeserializationContext ctxt)

Overrides com.fasterxml.jackson.databind.JsonDeserializer.getNullValue.

Implements com.fasterxml.jackson.databind.deser.NullValueProvider.getNullValue.

Method that can be called to determine value to be used for representing null values (values deserialized when JSON token is JsonToken#VALUE_NULL).

public Boolean
supportsUpdate(DeserializationConfig config)

Overrides com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.supportsUpdate.

Introspection method that may be called to see whether deserializer supports update of an existing value (aka "merging") or not.

Inherited from com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer:
_deserializeAnyScalar_deserializeContainerNoRecursion_deserializeObjectAtName_deserializeRareScalar_fromBigDecimal_fromEmbedded_fromFloat_fromInt_fromInt_handleDuplicateFieldcreateContextualdeserializeWithTypeisCachablelogicalTypeupdateObject

Field Detail

instanceback to summary
private static final JsonNodeDeserializer instance

Singleton instance of generic deserializer for JsonNode. Only used for types other than JSON Object and Array.

Constructor Detail

JsonNodeDeserializerback to summary
protected JsonNodeDeserializer()
JsonNodeDeserializerback to summary
protected JsonNodeDeserializer(JsonNodeDeserializer base, boolean mergeArrays, boolean mergeObjects)

Method Detail

_createWithMergeback to summary
protected JsonDeserializer<?> _createWithMerge(boolean mergeArrays, boolean mergeObjects)

Implements abstract com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer._createWithMerge.

Annotations
@Override
deserializeback to summary
public JsonNode deserialize(JsonParser p, DeserializationContext ctxt) throws IOException

Implements abstract com.fasterxml.jackson.databind.JsonDeserializer.deserialize.

Implementation that will produce types of any JSON nodes; not just one deserializer is registered to handle (in case of more specialized handler). Overridden by typed sub-classes for more thorough checking

Parameters
p:JsonParser

Doc from com.fasterxml.jackson.databind.JsonDeserializer.deserialize.

Parser used for reading JSON content

ctxt:DeserializationContext

Doc from com.fasterxml.jackson.databind.JsonDeserializer.deserialize.

Context that can be used to access information about this deserialization activity.

Returns:JsonNode

Doc from com.fasterxml.jackson.databind.JsonDeserializer.deserialize.

Deserialized value

Annotations
@Override
getAbsentValueback to summary
public Object getAbsentValue(DeserializationContext ctxt)

Overrides com.fasterxml.jackson.databind.JsonDeserializer.getAbsentValue.

Overrides default com.fasterxml.jackson.databind.deser.NullValueProvider.getAbsentValue.

Overridden variant to ensure that absent values are NOT coerced into NullNodes, unlike incoming null values.

Annotations
@Override
getDeserializerback to summary
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass)

Factory method for accessing deserializer for specific node type

getNullValueback to summary
public JsonNode getNullValue(DeserializationContext ctxt)

Overrides com.fasterxml.jackson.databind.JsonDeserializer.getNullValue.

Implements com.fasterxml.jackson.databind.deser.NullValueProvider.getNullValue.

Doc from com.fasterxml.jackson.databind.JsonDeserializer.getNullValue.

Method that can be called to determine value to be used for representing null values (values deserialized when JSON token is JsonToken#VALUE_NULL). Usually this is simply Java null, but for some types (especially primitives) it may be necessary to use non-null values.

This method may be called once, or multiple times, depending on what getNullAccessPattern() returns.

Default implementation simply returns null.

Annotations
@Override
supportsUpdateback to summary
public Boolean supportsUpdate(DeserializationConfig config)

Overrides com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.supportsUpdate.

Doc from com.fasterxml.jackson.databind.JsonDeserializer.supportsUpdate.

Introspection method that may be called to see whether deserializer supports update of an existing value (aka "merging") or not. Return value should either be Boolean#FALSE if update is not supported at all (immutable values); Boolean#TRUE if update should usually work (regular POJOs, for example), or null if this is either not known, or may sometimes work.

Information gathered is typically used to either prevent merging update for property (either by skipping, if based on global defaults; or by exception during deserializer construction if explicit attempt made) if Boolean#FALSE returned, or inclusion if Boolean#TRUE is specified. If "unknown" case (null returned) behavior is to exclude property if global defaults used; or to allow if explicit per-type or property merging is defined.

Default implementation returns null to allow explicit per-type or per-property attempts.

Annotations
@Override
com.fasterxml.jackson.databind.deser.std back to summary

pack-priv final Class JsonNodeDeserializer.ArrayDeserializer

extends BaseNodeDeserializer<ArrayNode>
Class Inheritance

Implementation used when declared type is specifically ArrayNode.

Field Summary

Modifier and TypeField and Description
protected static final JsonNodeDeserializer.ArrayDeserializer
private static final long
Inherited from com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer:
_mergeArrays_mergeObjects_supportsUpdates

Constructor Summary

AccessConstructor and Description
protected
protected
ArrayDeserializer(JsonNodeDeserializer.ArrayDeserializer base, boolean mergeArrays, boolean mergeObjects)

Method Summary

Modifier and TypeMethod and Description
protected JsonDeserializer<?>
_createWithMerge(boolean mergeArrays, boolean mergeObjects)

Implements abstract com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer._createWithMerge.

public ArrayNode
deserialize(JsonParser
Parser used for reading JSON content
p
,
DeserializationContext
Context that can be used to access information about this deserialization activity.
ctxt
)

Implements abstract com.fasterxml.jackson.databind.JsonDeserializer.deserialize.

Method that can be called to ask implementation to deserialize JSON content into the value type this serializer handles.

public ArrayNode
deserialize(JsonParser p, DeserializationContext ctxt, ArrayNode arrayNode)

Overrides com.fasterxml.jackson.databind.JsonDeserializer.deserialize.

Variant needed to support both root-level updateValue() and merging.

public static JsonNodeDeserializer.ArrayDeserializer
Inherited from com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer:
_deserializeAnyScalar_deserializeContainerNoRecursion_deserializeObjectAtName_deserializeRareScalar_fromBigDecimal_fromEmbedded_fromFloat_fromInt_fromInt_handleDuplicateFieldcreateContextualdeserializeWithTypeisCachablelogicalTypesupportsUpdateupdateObject

Field Detail

_instanceback to summary
protected static final JsonNodeDeserializer.ArrayDeserializer _instance
serialVersionUIDback to summary
private static final long serialVersionUID

Hides com.fasterxml.jackson.databind.deser.std.StdDeserializer.serialVersionUID.

Constructor Detail

ArrayDeserializerback to summary
protected ArrayDeserializer()
ArrayDeserializerback to summary
protected ArrayDeserializer(JsonNodeDeserializer.ArrayDeserializer base, boolean mergeArrays, boolean mergeObjects)

Method Detail

_createWithMergeback to summary
protected JsonDeserializer<?> _createWithMerge(boolean mergeArrays, boolean mergeObjects)

Implements abstract com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer._createWithMerge.

Annotations
@Override
deserializeback to summary
public ArrayNode deserialize(JsonParser p, DeserializationContext ctxt) throws IOException

Implements abstract com.fasterxml.jackson.databind.JsonDeserializer.deserialize.

Doc from com.fasterxml.jackson.databind.JsonDeserializer.deserialize.

Method that can be called to ask implementation to deserialize JSON content into the value type this serializer handles. Returned instance is to be constructed by method itself.

Pre-condition for this method is that the parser points to the first event that is part of value to deserializer (and which is never JSON 'null' literal, more on this below): for simple types it may be the only value; and for structured types the Object start marker or a FIELD_NAME.

The two possible input conditions for structured types result from polymorphism via fields. In the ordinary case, Jackson calls this method when it has encountered an OBJECT_START, and the method implementation must advance to the next token to see the first field name. If the application configures polymorphism via a field, then the object looks like the following.

      {
          "@class": "class name",
          ...
      }
  
Jackson consumes the two tokens (the @class field name and its value) in order to learn the class and select the deserializer. Thus, the stream is pointing to the FIELD_NAME for the first field after the @class. Thus, if you want your method to work correctly both with and without polymorphism, you must begin your method with:
       if (p.currentToken() == JsonToken.START_OBJECT) {
         p.nextToken();
       }
  
This results in the stream pointing to the field name, so that the two conditions align.

Post-condition is that the parser will point to the last event that is part of deserialized value (or in case deserialization fails, event that was not recognized or usable, which may be the same event as the one it pointed to upon call).

Handling null values (JsonToken.VALUE_NULL)
: Note that this method is never called for the JSON null literal to avoid every deserializer from having to handle null values. Instead, the JsonDeserializer#getNullValue(DeserializationContext) method is called to produce a null value. To influence null handling, custom deserializers should override JsonDeserializer#getNullValue(DeserializationContext) and usually also JsonDeserializer#getNullAccessPattern().

Parameters
p:JsonParser

Parser used for reading JSON content

ctxt:DeserializationContext

Context that can be used to access information about this deserialization activity.

Returns:ArrayNode

Deserialized value

Annotations
@Override
deserializeback to summary
public ArrayNode deserialize(JsonParser p, DeserializationContext ctxt, ArrayNode arrayNode) throws IOException

Overrides com.fasterxml.jackson.databind.JsonDeserializer.deserialize.

Variant needed to support both root-level updateValue() and merging.

Annotations
@Override
getInstanceback to summary
public static JsonNodeDeserializer.ArrayDeserializer getInstance()
com.fasterxml.jackson.databind.deser.std back to summary

pack-priv final Class JsonNodeDeserializer.ObjectDeserializer

extends BaseNodeDeserializer<ObjectNode>
Class Inheritance

Implementation used when declared type is specifically ObjectNode.

Field Summary

Modifier and TypeField and Description
protected static final JsonNodeDeserializer.ObjectDeserializer
private static final long
Inherited from com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer:
_mergeArrays_mergeObjects_supportsUpdates

Constructor Summary

AccessConstructor and Description
protected
protected
ObjectDeserializer(JsonNodeDeserializer.ObjectDeserializer base, boolean mergeArrays, boolean mergeObjects)

Method Summary

Modifier and TypeMethod and Description
protected JsonDeserializer<?>
_createWithMerge(boolean mergeArrays, boolean mergeObjects)

Implements abstract com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer._createWithMerge.

public ObjectNode
deserialize(JsonParser
Parser used for reading JSON content
p
,
DeserializationContext
Context that can be used to access information about this deserialization activity.
ctxt
)

Implements abstract com.fasterxml.jackson.databind.JsonDeserializer.deserialize.

Method that can be called to ask implementation to deserialize JSON content into the value type this serializer handles.

public ObjectNode
deserialize(JsonParser p, DeserializationContext ctxt, ObjectNode node)

Overrides com.fasterxml.jackson.databind.JsonDeserializer.deserialize.

Variant needed to support both root-level `updateValue()` and merging.

public static JsonNodeDeserializer.ObjectDeserializer
Inherited from com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer:
_deserializeAnyScalar_deserializeContainerNoRecursion_deserializeObjectAtName_deserializeRareScalar_fromBigDecimal_fromEmbedded_fromFloat_fromInt_fromInt_handleDuplicateFieldcreateContextualdeserializeWithTypeisCachablelogicalTypesupportsUpdateupdateObject

Field Detail

_instanceback to summary
protected static final JsonNodeDeserializer.ObjectDeserializer _instance
serialVersionUIDback to summary
private static final long serialVersionUID

Hides com.fasterxml.jackson.databind.deser.std.StdDeserializer.serialVersionUID.

Constructor Detail

ObjectDeserializerback to summary
protected ObjectDeserializer()
ObjectDeserializerback to summary
protected ObjectDeserializer(JsonNodeDeserializer.ObjectDeserializer base, boolean mergeArrays, boolean mergeObjects)

Method Detail

_createWithMergeback to summary
protected JsonDeserializer<?> _createWithMerge(boolean mergeArrays, boolean mergeObjects)

Implements abstract com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer._createWithMerge.

Annotations
@Override
deserializeback to summary
public ObjectNode deserialize(JsonParser p, DeserializationContext ctxt) throws IOException

Implements abstract com.fasterxml.jackson.databind.JsonDeserializer.deserialize.

Doc from com.fasterxml.jackson.databind.JsonDeserializer.deserialize.

Method that can be called to ask implementation to deserialize JSON content into the value type this serializer handles. Returned instance is to be constructed by method itself.

Pre-condition for this method is that the parser points to the first event that is part of value to deserializer (and which is never JSON 'null' literal, more on this below): for simple types it may be the only value; and for structured types the Object start marker or a FIELD_NAME.

The two possible input conditions for structured types result from polymorphism via fields. In the ordinary case, Jackson calls this method when it has encountered an OBJECT_START, and the method implementation must advance to the next token to see the first field name. If the application configures polymorphism via a field, then the object looks like the following.

      {
          "@class": "class name",
          ...
      }
  
Jackson consumes the two tokens (the @class field name and its value) in order to learn the class and select the deserializer. Thus, the stream is pointing to the FIELD_NAME for the first field after the @class. Thus, if you want your method to work correctly both with and without polymorphism, you must begin your method with:
       if (p.currentToken() == JsonToken.START_OBJECT) {
         p.nextToken();
       }
  
This results in the stream pointing to the field name, so that the two conditions align.

Post-condition is that the parser will point to the last event that is part of deserialized value (or in case deserialization fails, event that was not recognized or usable, which may be the same event as the one it pointed to upon call).

Handling null values (JsonToken.VALUE_NULL)
: Note that this method is never called for the JSON null literal to avoid every deserializer from having to handle null values. Instead, the JsonDeserializer#getNullValue(DeserializationContext) method is called to produce a null value. To influence null handling, custom deserializers should override JsonDeserializer#getNullValue(DeserializationContext) and usually also JsonDeserializer#getNullAccessPattern().

Parameters
p:JsonParser

Parser used for reading JSON content

ctxt:DeserializationContext

Context that can be used to access information about this deserialization activity.

Returns:ObjectNode

Deserialized value

Annotations
@Override
deserializeback to summary
public ObjectNode deserialize(JsonParser p, DeserializationContext ctxt, ObjectNode node) throws IOException

Overrides com.fasterxml.jackson.databind.JsonDeserializer.deserialize.

Variant needed to support both root-level `updateValue()` and merging.

Annotations
@Override
Since
2.9
getInstanceback to summary
public static JsonNodeDeserializer.ObjectDeserializer getInstance()