Package org.codehaus.jackson.node
Class ContainerNode
- java.lang.Object
-
- org.codehaus.jackson.JsonNode
-
- org.codehaus.jackson.node.BaseJsonNode
-
- org.codehaus.jackson.node.ContainerNode
-
- All Implemented Interfaces:
java.lang.Iterable<JsonNode>
,JsonSerializable
,JsonSerializableWithType
- Direct Known Subclasses:
ArrayNode
,ObjectNode
public abstract class ContainerNode extends BaseJsonNode
This intermediate base class is used for all container nodes, specifically, array and object nodes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
ContainerNode.NoNodesIterator
protected static class
ContainerNode.NoStringsIterator
-
Field Summary
-
Fields inherited from class org.codehaus.jackson.JsonNode
NO_NODES, NO_STRINGS
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ContainerNode(JsonNodeFactory nc)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description ArrayNode
arrayNode()
Factory method that constructs and returns an emptyArrayNode
Construction is done using registeredJsonNodeFactory
.java.lang.String
asText()
Method that will return valid String representation of the container value, if the node is a value node (methodJsonNode.isValueNode()
returns true), otherwise empty String.abstract JsonToken
asToken()
Method that can be used for efficient type detection when using stream abstraction for traversing nodes.BinaryNode
binaryNode(byte[] data)
BinaryNode
binaryNode(byte[] data, int offset, int length)
BooleanNode
booleanNode(boolean v)
abstract ObjectNode
findParent(java.lang.String fieldName)
Method for finding a JSON Object that contains specified field, within this node or its descendants.abstract java.util.List<JsonNode>
findParents(java.lang.String fieldName, java.util.List<JsonNode> foundSoFar)
abstract JsonNode
findValue(java.lang.String fieldName)
Method for finding a JSON Object field with specified name in this node or its child nodes, and returning value it has.abstract java.util.List<JsonNode>
findValues(java.lang.String fieldName, java.util.List<JsonNode> foundSoFar)
abstract java.util.List<java.lang.String>
findValuesAsText(java.lang.String fieldName, java.util.List<java.lang.String> foundSoFar)
abstract JsonNode
get(int index)
Method for accessing value of the specified element of an array node.abstract JsonNode
get(java.lang.String fieldName)
Method for accessing value of the specified field of an object node.java.lang.String
getValueAsText()
Method that will return valid String representation of the container value, if the node is a value node (methodJsonNode.isValueNode()
returns true), otherwise null.boolean
isContainerNode()
Method that returns true for container nodes: Arrays and Objects.NullNode
nullNode()
NumericNode
numberNode(byte v)
NumericNode
numberNode(double v)
NumericNode
numberNode(float v)
NumericNode
numberNode(int v)
NumericNode
numberNode(long v)
NumericNode
numberNode(short v)
NumericNode
numberNode(java.math.BigDecimal v)
ObjectNode
objectNode()
Factory method that constructs and returns an emptyObjectNode
Construction is done using registeredJsonNodeFactory
.POJONode
POJONode(java.lang.Object pojo)
abstract ContainerNode
removeAll()
Method for removing all children container has (if any)abstract int
size()
Method that returns number of child nodes this node contains: for Array nodes, number of child elements, for Object nodes, number of fields, and for all other nodes 0.TextNode
textNode(java.lang.String text)
-
Methods inherited from class org.codehaus.jackson.node.BaseJsonNode
findPath, getNumberType, serialize, serializeWithType, traverse
-
Methods inherited from class org.codehaus.jackson.JsonNode
asBoolean, asBoolean, asDouble, asDouble, asInt, asInt, asLong, asLong, equals, findParents, findValues, findValuesAsText, getBigIntegerValue, getBinaryValue, getBooleanValue, getDecimalValue, getDoubleValue, getElements, getFieldNames, getFields, getIntValue, getLongValue, getNumberValue, getPath, getPath, getTextValue, getValueAsBoolean, getValueAsBoolean, getValueAsDouble, getValueAsDouble, getValueAsInt, getValueAsInt, getValueAsLong, getValueAsLong, has, has, isArray, isBigDecimal, isBigInteger, isBinary, isBoolean, isDouble, isFloatingPointNumber, isInt, isIntegralNumber, isLong, isMissingNode, isNull, isNumber, isObject, isPojo, isTextual, isValueNode, iterator, path, path, toString, with
-
-
-
-
Constructor Detail
-
ContainerNode
protected ContainerNode(JsonNodeFactory nc)
-
-
Method Detail
-
isContainerNode
public boolean isContainerNode()
Description copied from class:JsonNode
Method that returns true for container nodes: Arrays and Objects.Note: one and only one of methods
JsonNode.isValueNode()
,JsonNode.isContainerNode()
andJsonNode.isMissingNode()
ever returns true for any given node.- Overrides:
isContainerNode
in classJsonNode
-
asToken
public abstract JsonToken asToken()
Description copied from class:BaseJsonNode
Method that can be used for efficient type detection when using stream abstraction for traversing nodes. Will return the firstJsonToken
that equivalent stream event would produce (for most nodes there is just one token but for structured/container types multiple)- Specified by:
asToken
in classBaseJsonNode
-
getValueAsText
public java.lang.String getValueAsText()
Description copied from class:JsonNode
Method that will return valid String representation of the container value, if the node is a value node (methodJsonNode.isValueNode()
returns true), otherwise null.Note: to serialize nodes of any type, you should call
JsonNode.toString()
instead.- Overrides:
getValueAsText
in classJsonNode
-
asText
public java.lang.String asText()
Description copied from class:JsonNode
Method that will return valid String representation of the container value, if the node is a value node (methodJsonNode.isValueNode()
returns true), otherwise empty String.
-
findValue
public abstract JsonNode findValue(java.lang.String fieldName)
Description copied from class:JsonNode
Method for finding a JSON Object field with specified name in this node or its child nodes, and returning value it has. If no matching field is found in this node or its descendants, returns null.- Overrides:
findValue
in classBaseJsonNode
- Parameters:
fieldName
- Name of field to look for- Returns:
- Value of first matching node found, if any; null if none
-
findParent
public abstract ObjectNode findParent(java.lang.String fieldName)
Description copied from class:JsonNode
Method for finding a JSON Object that contains specified field, within this node or its descendants. If no matching field is found in this node or its descendants, returns null.- Overrides:
findParent
in classBaseJsonNode
- Parameters:
fieldName
- Name of field to look for- Returns:
- Value of first matching node found, if any; null if none
-
findValues
public abstract java.util.List<JsonNode> findValues(java.lang.String fieldName, java.util.List<JsonNode> foundSoFar)
- Overrides:
findValues
in classBaseJsonNode
-
findParents
public abstract java.util.List<JsonNode> findParents(java.lang.String fieldName, java.util.List<JsonNode> foundSoFar)
- Overrides:
findParents
in classBaseJsonNode
-
findValuesAsText
public abstract java.util.List<java.lang.String> findValuesAsText(java.lang.String fieldName, java.util.List<java.lang.String> foundSoFar)
- Overrides:
findValuesAsText
in classBaseJsonNode
-
size
public abstract int size()
Description copied from class:JsonNode
Method that returns number of child nodes this node contains: for Array nodes, number of child elements, for Object nodes, number of fields, and for all other nodes 0.
-
get
public abstract JsonNode get(int index)
Description copied from class:JsonNode
Method for accessing value of the specified element of an array node. For other nodes, null is always returned.For array nodes, index specifies exact location within array and allows for efficient iteration over child elements (underlying storage is guaranteed to be efficiently indexable, i.e. has random-access to elements). If index is less than 0, or equal-or-greater than
node.size()
, null is returned; no exception is thrown for any index.
-
get
public abstract JsonNode get(java.lang.String fieldName)
Description copied from class:JsonNode
Method for accessing value of the specified field of an object node. If this node is not an object (or it does not have a value for specified field name), or if there is no field with such name, null is returned.
-
arrayNode
public final ArrayNode arrayNode()
Factory method that constructs and returns an emptyArrayNode
Construction is done using registeredJsonNodeFactory
.
-
objectNode
public final ObjectNode objectNode()
Factory method that constructs and returns an emptyObjectNode
Construction is done using registeredJsonNodeFactory
.
-
nullNode
public final NullNode nullNode()
-
booleanNode
public final BooleanNode booleanNode(boolean v)
-
numberNode
public final NumericNode numberNode(byte v)
-
numberNode
public final NumericNode numberNode(short v)
-
numberNode
public final NumericNode numberNode(int v)
-
numberNode
public final NumericNode numberNode(long v)
-
numberNode
public final NumericNode numberNode(float v)
-
numberNode
public final NumericNode numberNode(double v)
-
numberNode
public final NumericNode numberNode(java.math.BigDecimal v)
-
textNode
public final TextNode textNode(java.lang.String text)
-
binaryNode
public final BinaryNode binaryNode(byte[] data)
-
binaryNode
public final BinaryNode binaryNode(byte[] data, int offset, int length)
-
POJONode
public final POJONode POJONode(java.lang.Object pojo)
-
removeAll
public abstract ContainerNode removeAll()
Method for removing all children container has (if any)- Returns:
- Container node itself (to allow method call chaining)
- Since:
- 1.3
-
-