Class BaseJsonNode
- java.lang.Object
-
- com.fasterxml.jackson.databind.JsonSerializable.Base
-
- com.fasterxml.jackson.databind.JsonNode
-
- com.fasterxml.jackson.databind.node.BaseJsonNode
-
- All Implemented Interfaces:
com.fasterxml.jackson.core.TreeNode,JsonSerializable,java.io.Serializable,java.lang.Iterable<JsonNode>
- Direct Known Subclasses:
ContainerNode,ValueNode
public abstract class BaseJsonNode extends JsonNode implements java.io.Serializable
Abstract base class common to all standardJsonNodeimplementations. The main addition here is that we declare that sub-classes must implementJsonSerializable. This simplifies object mapping aspects a bit, as no external serializers are needed.Since 2.10, all implements have been
Serializable.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.JsonNode
JsonNode.OverwriteMode
-
Nested classes/interfaces inherited from interface com.fasterxml.jackson.databind.JsonSerializable
JsonSerializable.Base
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseJsonNode()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.math.BigInteger_bigIntFromBigDec(java.math.BigDecimal value)protected com.fasterxml.jackson.core.JsonPointer_jsonPointerIfValid(java.lang.String exprOrProperty)protected <T> T_reportWrongNodeOperation(java.lang.String msgTemplate, java.lang.Object... args)protected <T> T_reportWrongNodeType(java.lang.String msgTemplate, java.lang.Object... args)Helper method that throwsUnsupportedOperationExceptionas a result of this node being of wrong typeprotected ArrayNode_withArray(com.fasterxml.jackson.core.JsonPointer origPtr, com.fasterxml.jackson.core.JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)protected ObjectNode_withObject(com.fasterxml.jackson.core.JsonPointer origPtr, com.fasterxml.jackson.core.JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)protected boolean_withXxxMayReplace(JsonNode node, JsonNode.OverwriteMode overwriteMode)protected void_withXxxVerifyReplace(com.fasterxml.jackson.core.JsonPointer origPtr, com.fasterxml.jackson.core.JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex, JsonNode toReplace)abstract com.fasterxml.jackson.core.JsonTokenasToken()Method that can be used for efficient type detection when using stream abstraction for traversing nodes.JsonNodefindPath(java.lang.String fieldName)Method similar toJsonNode.findValue(java.lang.String), but that will return a "missing node" instead of null if no field is found.abstract inthashCode()com.fasterxml.jackson.core.JsonParser.NumberTypenumberType()Returns code that identifies type of underlying numeric value, if (and only if) node is a number node.JsonNoderequired(int index)Method is functionally equivalent topath(index).required()and can be used to check that this node is anArrayNode(that is, represents JSON Array value) and has value for specifiedindex(but note that value may be explicit JSON null value).JsonNoderequired(java.lang.String fieldName)Method is functionally equivalent topath(fieldName).required()and can be used to check that this node is anObjectNode(that is, represents JSON Object value) and has value for specified property with keyfieldName(but note that value may be explicit JSON null value).abstract voidserialize(com.fasterxml.jackson.core.JsonGenerator g, SerializerProvider ctxt)Method called to serialize node instances using given generator.abstract voidserializeWithType(com.fasterxml.jackson.core.JsonGenerator g, SerializerProvider ctxt, TypeSerializer typeSer)Type information is needed, even if JsonNode instances are "plain" JSON, since they may be mixed with other types.java.lang.StringtoPrettyString()Alternative toJsonNode.toString()that will serialize this node using Jackson default pretty-printer.java.lang.StringtoString()Method that will produce (as of Jackson 2.10) valid JSON using default settings of databind, as String.com.fasterxml.jackson.core.JsonParsertraverse()com.fasterxml.jackson.core.JsonParsertraverse(com.fasterxml.jackson.core.ObjectCodec codec)ArrayNodewithArray(com.fasterxml.jackson.core.JsonPointer ptr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)Method that can be called on Object or Array nodes, to access a Array-valued node pointed to by givenJsonPointer, if such a node exists: or if not, an attempt is made to create one and return it.ObjectNodewithObject(com.fasterxml.jackson.core.JsonPointer ptr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)Method that can be called on Object or Array nodes, to access a Object-valued node pointed to by givenJsonPointer, if such a node exists: or if not, an attempt is made to create one and return it.-
Methods inherited from class com.fasterxml.jackson.databind.JsonNode
_at, _reportRequiredViolation, _this, asBoolean, asBoolean, asDouble, asDouble, asInt, asInt, asLong, asLong, asText, asText, at, at, bigIntegerValue, binaryValue, booleanValue, canConvertToExactIntegral, canConvertToInt, canConvertToLong, decimalValue, deepCopy, doubleValue, elements, equals, equals, fieldNames, fields, findParent, findParents, findParents, findValue, findValues, findValues, findValuesAsText, findValuesAsText, floatValue, get, get, getNodeType, has, has, hasNonNull, hasNonNull, intValue, isArray, isBigDecimal, isBigInteger, isBinary, isBoolean, isContainerNode, isDouble, isEmpty, isFloat, isFloatingPointNumber, isInt, isIntegralNumber, isLong, isMissingNode, isNull, isNumber, isObject, isPojo, isShort, isTextual, isValueNode, iterator, longValue, numberValue, path, path, properties, require, requiredAt, requiredAt, requireNonNull, shortValue, size, textValue, with, withArray, withArray, withArray, withArrayProperty, withObject, withObject, withObject, withObjectProperty
-
Methods inherited from class com.fasterxml.jackson.databind.JsonSerializable.Base
isEmpty
-
-
-
-
Method Detail
-
findPath
public final JsonNode findPath(java.lang.String fieldName)
Description copied from class:JsonNodeMethod similar toJsonNode.findValue(java.lang.String), but that will return a "missing node" instead of null if no field is found. Missing node is a specific kind of node for whichJsonNode.isMissingNode()returns true; and all value access methods return empty or missing value.
-
hashCode
public abstract int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
required
public JsonNode required(java.lang.String fieldName)
Description copied from class:JsonNodeMethod is functionally equivalent topath(fieldName).required()and can be used to check that this node is anObjectNode(that is, represents JSON Object value) and has value for specified property with keyfieldName(but note that value may be explicit JSON null value). If this node is Object Node and has value for specified property, matching value is returned; otherwiseIllegalArgumentExceptionis thrown.
-
required
public JsonNode required(int index)
Description copied from class:JsonNodeMethod is functionally equivalent topath(index).required()and can be used to check that this node is anArrayNode(that is, represents JSON Array value) and has value for specifiedindex(but note that value may be explicit JSON null value). If this node is Array Node and has value for specified index, value at index is returned; otherwiseIllegalArgumentExceptionis thrown.
-
traverse
public com.fasterxml.jackson.core.JsonParser traverse()
- Specified by:
traversein interfacecom.fasterxml.jackson.core.TreeNode
-
traverse
public com.fasterxml.jackson.core.JsonParser traverse(com.fasterxml.jackson.core.ObjectCodec codec)
- Specified by:
traversein interfacecom.fasterxml.jackson.core.TreeNode
-
asToken
public abstract com.fasterxml.jackson.core.JsonToken asToken()
Method that can be used for efficient type detection when using stream abstraction for traversing nodes. Will return the firstJsonTokenthat equivalent stream event would produce (for most nodes there is just one token but for structured/container types multiple)- Specified by:
asTokenin interfacecom.fasterxml.jackson.core.TreeNode
-
numberType
public com.fasterxml.jackson.core.JsonParser.NumberType numberType()
Returns code that identifies type of underlying numeric value, if (and only if) node is a number node.- Specified by:
numberTypein interfacecom.fasterxml.jackson.core.TreeNode
-
withObject
public ObjectNode withObject(com.fasterxml.jackson.core.JsonPointer ptr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)
Description copied from class:JsonNodeMethod that can be called on Object or Array nodes, to access a Object-valued node pointed to by givenJsonPointer, if such a node exists: or if not, an attempt is made to create one and return it. For example, on document{ "a" : { "b" : { "c" : 13 } } }calling method withJsonPointerof/a/bwould returnObjectNode{ "c" : 13 }In cases where path leads to "missing" nodes, a path is created. So, for example, on above document, and
JsonPointerof/a/xan emptyObjectNodewould be returned and the document would look like:{ "a" : { "b" : { "c" : 13 }, "x" : { } } }Finally, if the path is incompatible with the document -- there is an existingJsonNodethrough which expression cannot go -- a replacement is attempted if (and only if) conversion is allowed as peroverwriteModepassed in. For example, with above document and expression of/a/b/c, conversion is allowed if passingOverwriteMode.SCALARSorOvewriteMode.ALL, and resulting document would look like:{ "a" : { "b" : { "c" : { } }, "x" : { } } }but if different modes (NONEorNULLS) is passed, an exception is thrown instead.- Overrides:
withObjectin classJsonNode- Parameters:
ptr- Pointer that indicates path to use forObjectNodevalue to return (potentially creating one as necessary)overwriteMode- Defines which node types may be converted in case of incompatibleJsonPointerexpression: if conversion not allowed,UnsupportedOperationExceptionis thrown.preferIndex- When creating a path (for empty or replacement), and path contains segment that may be an array index (simple integer number like3), whether to construct anArrayNode(true) orObjectNode(false). In latter case matching property with quoted number (like"3") is used within Object.- Returns:
ObjectNodefound or created
-
_withObject
protected ObjectNode _withObject(com.fasterxml.jackson.core.JsonPointer origPtr, com.fasterxml.jackson.core.JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)
-
_withXxxVerifyReplace
protected void _withXxxVerifyReplace(com.fasterxml.jackson.core.JsonPointer origPtr, com.fasterxml.jackson.core.JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex, JsonNode toReplace)
-
_withXxxMayReplace
protected boolean _withXxxMayReplace(JsonNode node, JsonNode.OverwriteMode overwriteMode)
-
withArray
public ArrayNode withArray(com.fasterxml.jackson.core.JsonPointer ptr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)
Description copied from class:JsonNodeMethod that can be called on Object or Array nodes, to access a Array-valued node pointed to by givenJsonPointer, if such a node exists: or if not, an attempt is made to create one and return it. For example, on document{ "a" : { "b" : [ 1, 2 ] } }calling method withJsonPointerof/a/bwould returnArray[ 1, 2 ]
In cases where path leads to "missing" nodes, a path is created. So, for example, on above document, and
JsonPointerof/a/xan emptyArrayNodewould be returned and the document would look like:{ "a" : { "b" : [ 1, 2 ], "x" : [ ] } }Finally, if the path is incompatible with the document -- there is an existingJsonNodethrough which expression cannot go -- a replacement is attempted if (and only if) conversion is allowed as peroverwriteModepassed in. For example, with above document and expression of/a/b/0, conversion is allowed if passingOverwriteMode.SCALARSorOvewriteMode.ALL, and resulting document would look like:{ "a" : { "b" : [ [ ], 2 ], "x" : [ ] } }but if different modes (NONEorNULLS) is passed, an exception is thrown instead.- Overrides:
withArrayin classJsonNode- Parameters:
ptr- Pointer that indicates path to use forArrayNodevalue to return (potentially creating it as necessary)overwriteMode- Defines which node types may be converted in case of incompatibleJsonPointerexpression: if conversion not allowed, an exception is thrown.preferIndex- When creating a path (for empty or replacement), and path contains segment that may be an array index (simple integer number like3), whether to construct anArrayNode(true) orObjectNode(false). In latter case matching property with quoted number (like"3") is used within Object.- Returns:
ArrayNodefound or created
-
_withArray
protected ArrayNode _withArray(com.fasterxml.jackson.core.JsonPointer origPtr, com.fasterxml.jackson.core.JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)
-
serialize
public abstract void serialize(com.fasterxml.jackson.core.JsonGenerator g, SerializerProvider ctxt) throws java.io.IOExceptionMethod called to serialize node instances using given generator.- Specified by:
serializein interfaceJsonSerializable- Throws:
java.io.IOException
-
serializeWithType
public abstract void serializeWithType(com.fasterxml.jackson.core.JsonGenerator g, SerializerProvider ctxt, TypeSerializer typeSer) throws java.io.IOExceptionType information is needed, even if JsonNode instances are "plain" JSON, since they may be mixed with other types.- Specified by:
serializeWithTypein interfaceJsonSerializable- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
Description copied from class:JsonNodeMethod that will produce (as of Jackson 2.10) valid JSON using default settings of databind, as String. If you want other kinds of JSON output (or output formatted using one of other Jackson-supported data formats) make sure to useObjectMapperorObjectWriterto serialize an instance, for example:String json = objectMapper.writeValueAsString(rootNode);
Note: method defined as abstract to ensure all implementation classes explicitly implement method, instead of relying on
Object.toString()definition.
-
toPrettyString
public java.lang.String toPrettyString()
Description copied from class:JsonNodeAlternative toJsonNode.toString()that will serialize this node using Jackson default pretty-printer.- Overrides:
toPrettyStringin classJsonNode
-
_reportWrongNodeType
protected <T> T _reportWrongNodeType(java.lang.String msgTemplate, java.lang.Object... args)Helper method that throwsUnsupportedOperationExceptionas a result of this node being of wrong type
-
_reportWrongNodeOperation
protected <T> T _reportWrongNodeOperation(java.lang.String msgTemplate, java.lang.Object... args)
-
_jsonPointerIfValid
protected com.fasterxml.jackson.core.JsonPointer _jsonPointerIfValid(java.lang.String exprOrProperty)
-
_bigIntFromBigDec
protected java.math.BigInteger _bigIntFromBigDec(java.math.BigDecimal value)
-
-