JSON
Version 1.0

org.codehaus.jackson.map
Class JsonNode

java.lang.Object
  extended by org.codehaus.jackson.map.JsonNode
Direct Known Subclasses:
ContainerNode, MissingNode, ValueNode

public abstract class JsonNode
extends Object

Base class for all JSON nodes, used with the "dynamic" (JSON type) mapper


Constructor Summary
protected JsonNode()
           
 
Method Summary
 void appendElement(JsonNode node)
           
abstract  boolean equals(Object o)
          Let's mark this standard method as abstract to ensure all implementation classes define it
 boolean getBooleanValue()
           
 BigDecimal getDecimalValue()
           
 double getDoubleValue()
           
 Iterator<JsonNode> getElements()
           
 JsonNode getElementValue(int index)
          Method for accessing value of the specified element of an array node.
 Iterator<String> getFieldNames()
           
 JsonNode getFieldValue(String fieldName)
          Method for accessing value of the specified field of an object node.
 Iterator<JsonNode> getFieldValues()
           
 int getIntValue()
           
 long getLongValue()
           
 Number getNumberValue()
           
abstract  JsonNode getPath(int index)
          This method is similar to getElementValue(int), except that instead of returning null if no such element exists (due to index being out of range, or this node not being an array), a "missing node" (node that returns true for isMissingNode()) will be returned.
abstract  JsonNode getPath(String fieldName)
          This method is similar to getFieldValue(java.lang.String), except that instead of returning null if no such value exists (due to this node not being an object, or object not having value for the specified field), a "missing node" (node that returns true for isMissingNode()) will be returned.
 String getTextValue()
           
abstract  String getValueAsText()
          Method that will return valid String representation of the container value, if the node is a value node (method isValueNode() returns true), otherwise null.
 void insertElement(int index, JsonNode value)
           
 boolean isArray()
           
 boolean isBigDecimal()
           
 boolean isBoolean()
           
 boolean isContainerNode()
          Method that returns true for container nodes: Arrays and Objects.
 boolean isDouble()
           
 boolean isFloatingPointNumber()
           
 boolean isInt()
           
 boolean isIntegralNumber()
           
 boolean isLong()
           
 boolean isMissingNode()
          Method that returns true for "virtual" nodes which represent missing entries constructed by path accessor methods when there is no actual node matching given criteria.
 boolean isNull()
           
 boolean isNumber()
           
 boolean isObject()
           
 boolean isTextual()
           
 boolean isValueNode()
          Method that returns true for all value nodes: ones that are not containers, and that do not represent "missing" nodes in the path.
 JsonNode removeElement(int index)
           
 JsonNode removeElement(String fieldName)
           
protected  JsonNode reportNoArrayMods()
           
protected  JsonNode reportNoObjectMods()
           
 JsonNode setElement(int index, JsonNode value)
           
 JsonNode setElement(String fieldName, JsonNode value)
           
 int size()
           
abstract  String toString()
          Let's mark this standard method as abstract to ensure all implementation classes define it
abstract  void writeTo(JsonGenerator jg)
          Method that can be called to serialize this node and all of its descendants using specified JSON generator.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JsonNode

protected JsonNode()
Method Detail

isValueNode

public boolean isValueNode()
Method that returns true for all value nodes: ones that are not containers, and that do not represent "missing" nodes in the path. Such value nodes represent String, Number, Boolean and null values from JSON.

Note: one and only one of methods isValueNode(), isContainerNode() and isMissingNode() ever returns true for any given node.


isContainerNode

public boolean isContainerNode()
Method that returns true for container nodes: Arrays and Objects.

Note: one and only one of methods isValueNode(), isContainerNode() and isMissingNode() ever returns true for any given node.


isMissingNode

public boolean isMissingNode()
Method that returns true for "virtual" nodes which represent missing entries constructed by path accessor methods when there is no actual node matching given criteria.

Note: one and only one of methods isValueNode(), isContainerNode() and isMissingNode() ever returns true for any given node.


isArray

public boolean isArray()

isObject

public boolean isObject()

isNumber

public boolean isNumber()

isIntegralNumber

public boolean isIntegralNumber()

isFloatingPointNumber

public boolean isFloatingPointNumber()

isInt

public boolean isInt()

isLong

public boolean isLong()

isDouble

public boolean isDouble()

isBigDecimal

public boolean isBigDecimal()

isTextual

public boolean isTextual()

isBoolean

public boolean isBoolean()

isNull

public boolean isNull()

getTextValue

public String getTextValue()

getBooleanValue

public boolean getBooleanValue()

getNumberValue

public Number getNumberValue()

getIntValue

public int getIntValue()

getLongValue

public long getLongValue()

getDoubleValue

public double getDoubleValue()

getDecimalValue

public BigDecimal getDecimalValue()

getElementValue

public JsonNode getElementValue(int index)
Method for accessing value of the specified element of an array node. If this node is not an array (or index is out of range), null will be returned.

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

getFieldValue

public JsonNode getFieldValue(String fieldName)
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), null is returned.

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

getValueAsText

public abstract String getValueAsText()
Method that will return valid String representation of the container value, if the node is a value node (method isValueNode() returns true), otherwise null.

Note: to serialize nodes of any type, you should call toString() instead.


size

public int size()
Returns:
For non-container nodes returns 0; for arrays number of contained elements, and for objects number of fields.

getElements

public Iterator<JsonNode> getElements()

getFieldNames

public Iterator<String> getFieldNames()

getFieldValues

public Iterator<JsonNode> getFieldValues()

appendElement

public void appendElement(JsonNode node)

insertElement

public void insertElement(int index,
                          JsonNode value)

removeElement

public JsonNode removeElement(int index)

removeElement

public JsonNode removeElement(String fieldName)

setElement

public JsonNode setElement(int index,
                           JsonNode value)

setElement

public JsonNode setElement(String fieldName,
                           JsonNode value)

getPath

public abstract JsonNode getPath(String fieldName)
This method is similar to getFieldValue(java.lang.String), except that instead of returning null if no such value exists (due to this node not being an object, or object not having value for the specified field), a "missing node" (node that returns true for isMissingNode()) will be returned. This allows for convenient and safe chained access via path calls.


getPath

public abstract JsonNode getPath(int index)
This method is similar to getElementValue(int), except that instead of returning null if no such element exists (due to index being out of range, or this node not being an array), a "missing node" (node that returns true for isMissingNode()) will be returned. This allows for convenient and safe chained access via path calls.


writeTo

public abstract void writeTo(JsonGenerator jg)
                      throws IOException,
                             JsonGenerationException
Method that can be called to serialize this node and all of its descendants using specified JSON generator.

Throws:
IOException
JsonGenerationException

toString

public abstract String toString()
Let's mark this standard method as abstract to ensure all implementation classes define it

Overrides:
toString in class Object

equals

public abstract boolean equals(Object o)
Let's mark this standard method as abstract to ensure all implementation classes define it

Overrides:
equals in class Object

reportNoArrayMods

protected JsonNode reportNoArrayMods()

reportNoObjectMods

protected JsonNode reportNoObjectMods()

JSON
Version 1.0

Apache License, Version 2.0