com.fasterxml.jackson.databind.node
Class ContainerNode<T extends ContainerNode<T>>

java.lang.Object
  extended by com.fasterxml.jackson.databind.JsonNode
      extended by com.fasterxml.jackson.databind.node.BaseJsonNode
          extended by com.fasterxml.jackson.databind.node.ContainerNode<T>
All Implemented Interfaces:
com.fasterxml.jackson.core.TreeNode, JsonSerializable, Iterable<JsonNode>
Direct Known Subclasses:
ArrayNode, ObjectNode

public abstract class ContainerNode<T extends ContainerNode<T>>
extends BaseJsonNode

This intermediate base class is used for all container nodes, specifically, array and object nodes.


Nested Class Summary
protected static class ContainerNode.NoNodesIterator
           
protected static class ContainerNode.NoStringsIterator
           
 
Field Summary
protected  JsonNodeFactory _nodeFactory
          We will keep a reference to the Object (usually TreeMapper) that can construct instances of nodes to add to this container node.
 
Fields inherited from class com.fasterxml.jackson.databind.JsonNode
NO_NODES, NO_STRINGS
 
Constructor Summary
protected ContainerNode(JsonNodeFactory nc)
           
 
Method Summary
 ArrayNode arrayNode()
          Factory method that constructs and returns an empty ArrayNode Construction is done using registered JsonNodeFactory.
 String asText()
          Method that will return a valid String representation of the container value, if the node is a value node (method JsonNode.isValueNode() returns true), otherwise empty String.
abstract  com.fasterxml.jackson.core.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(String fieldName)
          Method for finding a JSON Object that contains specified field, within this node or its descendants.
abstract  List<JsonNode> findParents(String fieldName, List<JsonNode> foundSoFar)
           
abstract  JsonNode findValue(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  List<JsonNode> findValues(String fieldName, List<JsonNode> foundSoFar)
           
abstract  List<String> findValuesAsText(String fieldName, List<String> foundSoFar)
           
abstract  JsonNode get(int index)
          Method for accessing value of the specified element of an array node.
abstract  JsonNode get(String fieldName)
          Method for accessing value of the specified field of an object node.
 boolean isContainerNode()
          Method that returns true for container nodes: Arrays and Objects.
 NullNode nullNode()
           
 NumericNode numberNode(BigDecimal v)
           
 NumericNode numberNode(byte v)
           
 NumericNode numberNode(double v)
           
 NumericNode numberNode(float v)
           
 NumericNode numberNode(int v)
           
 NumericNode numberNode(long v)
           
 NumericNode numberNode(short v)
           
 ObjectNode objectNode()
          Factory method that constructs and returns an empty ObjectNode Construction is done using registered JsonNodeFactory.
 POJONode POJONode(Object pojo)
           
abstract  T 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(String text)
           
 
Methods inherited from class com.fasterxml.jackson.databind.node.BaseJsonNode
findPath, numberType, serialize, serializeWithType, traverse
 
Methods inherited from class com.fasterxml.jackson.databind.JsonNode
asBoolean, asBoolean, asDouble, asDouble, asInt, asInt, asLong, asLong, bigIntegerValue, binaryValue, booleanValue, canConvertToInt, canConvertToLong, decimalValue, deepCopy, doubleValue, elements, equals, fieldNames, fields, findParents, findValues, findValuesAsText, has, has, intValue, isArray, isBigDecimal, isBigInteger, isBinary, isBoolean, isDouble, isFloatingPointNumber, isInt, isIntegralNumber, isLong, isMissingNode, isNull, isNumber, isObject, isPojo, isTextual, isValueNode, iterator, longValue, numberValue, path, path, textValue, toString, with, withArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_nodeFactory

protected final JsonNodeFactory _nodeFactory
We will keep a reference to the Object (usually TreeMapper) that can construct instances of nodes to add to this container node.

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() and JsonNode.isMissingNode() ever returns true for any given node.

Overrides:
isContainerNode in class JsonNode

asToken

public abstract com.fasterxml.jackson.core.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 first JsonToken that equivalent stream event would produce (for most nodes there is just one token but for structured/container types multiple)

Specified by:
asToken in interface com.fasterxml.jackson.core.TreeNode
Specified by:
asToken in class BaseJsonNode

asText

public String asText()
Description copied from class: JsonNode
Method that will return a valid String representation of the container value, if the node is a value node (method JsonNode.isValueNode() returns true), otherwise empty String.

Specified by:
asText in class JsonNode

findValue

public abstract JsonNode findValue(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 class BaseJsonNode
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(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 class BaseJsonNode
Parameters:
fieldName - Name of field to look for
Returns:
Value of first matching node found, if any; null if none

findValues

public abstract List<JsonNode> findValues(String fieldName,
                                          List<JsonNode> foundSoFar)
Overrides:
findValues in class BaseJsonNode

findParents

public abstract List<JsonNode> findParents(String fieldName,
                                           List<JsonNode> foundSoFar)
Overrides:
findParents in class BaseJsonNode

findValuesAsText

public abstract List<String> findValuesAsText(String fieldName,
                                              List<String> foundSoFar)
Overrides:
findValuesAsText in class BaseJsonNode

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.

Overrides:
size in class JsonNode
Returns:
For non-container nodes returns 0; for arrays number of contained elements, and for objects number of fields.

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.

Overrides:
get in class JsonNode
Returns:
Node that represent value of the specified element, if this node is an array and has specified element. Null otherwise.

get

public abstract JsonNode get(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.

Overrides:
get in class JsonNode
Returns:
Node that represent value of the specified field, if this node is an object and has value for the specified field. Null otherwise.

arrayNode

public final ArrayNode arrayNode()
Factory method that constructs and returns an empty ArrayNode Construction is done using registered JsonNodeFactory.


objectNode

public final ObjectNode objectNode()
Factory method that constructs and returns an empty ObjectNode Construction is done using registered JsonNodeFactory.


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(BigDecimal v)

textNode

public final TextNode textNode(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(Object pojo)

removeAll

public abstract T removeAll()
Method for removing all children container has (if any)

Returns:
Container node itself (to allow method call chaining)


Copyright © 2012 fasterxml.com. All Rights Reserved.