Top Description Fields Constructors Methods
com.fasterxml.jackson.databind.node

public Class JsonNodeFactory

extends Object
implements Serializable, JsonNodeCreator
Class Inheritance
All Implemented Interfaces
com.fasterxml.jackson.databind.node.JsonNodeCreator, java.io.Serializable
Imports
java.math.BigDecimal, .BigInteger, com.fasterxml.jackson.databind.JsonNode, com.fasterxml.jackson.databind.util.RawValue

Base class that specifies methods for getting access to Node instances (newly constructed, or shared, depending on type), as well as basic implementation of the methods. Designed to be sub-classed if extended functionality (additions to behavior of node types, mostly) is needed.

One configuration option in the default implementation is that of whether DecimalNode instances must be built with exact representations of BigDecimal instances; or to use "normalized" instance. This has quite an influence since, for instance, a BigDecimal (and, therefore, a DecimalNode) constructed from input string "1.0" and another constructed with input string "1.00" will not be equal unless normalized since their scale differs (1 in the first case, 2 in the second case). Normalization, if enabled, means simply calling BigDecimal#stripTrailingZeros().

Note that configuration of "normalization" changed in 2.15: while JsonNodeFactory still has a default setting, the intent is to deprecate and remove this, to be replaced by new com.fasterxml.jackson.databind.cfg.JsonNodeFeature#STRIP_TRAILING_BIGDECIMAL_ZEROES setting. Default setting in 2.15 is to ENABLE normalization: this will likely change at latest in Jackson 3.0 (to leave BigDecimal values as they are). Note, too, that this factory will no longer handle this normalization (if enabled): caller (like com.fasterxml.jackson.databind.deser.std.JsonNodeDeserializer) is expected to handle it.

Field Summary

Modifier and TypeField and Description
private final boolean
public static final JsonNodeFactory
instance

Default singleton instance that construct "standard" node instances: given that this class is stateless, a globally shared singleton can be used.

protected static final int
MAX_ELEMENT_INDEX_FOR_INSERT

Constant that defines maximum JsonPointer element index we use for inserts.

private static final long

Constructor Summary

AccessConstructor and Description
public
JsonNodeFactory(boolean
see Class description on "BigDecimal normalization"
bigDecimalExact
)

protected
JsonNodeFactory()

Default constructor.

Method Summary

Modifier and TypeMethod and Description
protected boolean
_inIntRange(long l)

public ArrayNode
arrayNode()

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.arrayNode.

Factory method for constructing an empty JSON Array node
public ArrayNode
arrayNode(int capacity)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.arrayNode.

Factory method for constructing a JSON Array node with an initial capacity
public BinaryNode
binaryNode(byte[] data)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.binaryNode.

Factory method for constructing a node that represents given binary data, and will get serialized as equivalent base64-encoded String value
public BinaryNode
binaryNode(byte[] data, int offset, int length)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.binaryNode.

Factory method for constructing a node that represents given binary data, and will get serialized as equivalent base64-encoded String value
public BooleanNode
booleanNode(boolean v)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.booleanNode.

Factory method for getting an instance of JSON boolean value (either literal 'true' or 'false')
public int
public JsonNode
public NullNode
nullNode()

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.nullNode.

Factory method for getting an instance of JSON null node (which represents literal null value)
public NumericNode
numberNode(byte v)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Factory method for getting an instance of JSON numeric value that expresses given 8-bit value
public ValueNode
numberNode(Byte value)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Alternate factory method that will handle wrapper value, which may be null.
public NumericNode
numberNode(short v)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Factory method for getting an instance of JSON numeric value that expresses given 16-bit integer value
public ValueNode
numberNode(Short value)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Alternate factory method that will handle wrapper value, which may be null.
public NumericNode
numberNode(int v)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Factory method for getting an instance of JSON numeric value that expresses given 32-bit integer value
public ValueNode
numberNode(Integer value)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Alternate factory method that will handle wrapper value, which may be null.
public NumericNode
numberNode(long v)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Factory method for getting an instance of JSON numeric value that expresses given 64-bit integer value
public ValueNode
numberNode(Long v)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Alternate factory method that will handle wrapper value, which may be null.
public ValueNode
numberNode(BigInteger v)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Factory method for getting an instance of JSON numeric value that expresses given unlimited range integer value
public NumericNode
numberNode(float v)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Factory method for getting an instance of JSON numeric value that expresses given 32-bit floating point value
public ValueNode
numberNode(Float value)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Alternate factory method that will handle wrapper value, which may be null.
public NumericNode
numberNode(double v)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Factory method for getting an instance of JSON numeric value that expresses given 64-bit floating point value
public ValueNode
numberNode(Double value)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Alternate factory method that will handle wrapper value, which may be null.
public ValueNode
numberNode(BigDecimal v)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Factory method for getting an instance of JSON numeric value that expresses given unlimited precision floating point value

Note that regardless whether the factory has been built to normalize decimal values (see class JavaDoc), the BigDecimal argument will NOT be modified by this method -- caller will need to handle normalization, if any.

public ObjectNode
objectNode()

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.objectNode.

Factory method for constructing an empty JSON Object ("struct") node
public ValueNode
pojoNode(Object pojo)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.pojoNode.

Factory method for constructing a wrapper for POJO ("Plain Old Java Object") objects; these will get serialized using data binding, usually as JSON Objects, but in some cases as JSON Strings or other node types.
public ValueNode
rawValueNode(RawValue value)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.rawValueNode.

Factory method to use for adding "raw values"; pre-encoded values that are included exactly as-is when node is serialized.
public TextNode
textNode(String text)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.textNode.

Factory method for constructing a node that represents JSON String value
public boolean
willStripTrailingBigDecimalZeroes()

Accessor needed by JsonNodeDeserializer.

public static JsonNodeFactory

Returns:

a factory instance with specified configuration
withExactBigDecimals
(boolean
If {code true} DISABLE normalization of BigDecimal values; if {code false} ENABLE normalization
bigDecimalExact
)

Return a factory instance with the desired behavior for BigDecimals

See JsonNodeFactory(boolean) for a full description.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_cfgBigDecimalExactback to summary
private final boolean _cfgBigDecimalExact

Deprecated

Annotations
@Deprecated
instanceback to summary
public static final JsonNodeFactory instance

Default singleton instance that construct "standard" node instances: given that this class is stateless, a globally shared singleton can be used.

MAX_ELEMENT_INDEX_FOR_INSERTback to summary
protected static final int MAX_ELEMENT_INDEX_FOR_INSERT

Constant that defines maximum JsonPointer element index we use for inserts.

serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

JsonNodeFactoryback to summary
public JsonNodeFactory(boolean bigDecimalExact)
Parameters
bigDecimalExact:boolean

see Class description on "BigDecimal normalization"

See Also
BigDecimal
JsonNodeFactoryback to summary
protected JsonNodeFactory()

Default constructor.

This calls JsonNodeFactory(boolean) with false as an argument.

Method Detail

_inIntRangeback to summary
protected boolean _inIntRange(long l)
arrayNodeback to summary
public ArrayNode arrayNode()

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.arrayNode.

Factory method for constructing an empty JSON Array node

Annotations
@Override
arrayNodeback to summary
public ArrayNode arrayNode(int capacity)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.arrayNode.

Factory method for constructing a JSON Array node with an initial capacity

Annotations
@Override
Since
2.8
binaryNodeback to summary
public BinaryNode binaryNode(byte[] data)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.binaryNode.

Factory method for constructing a node that represents given binary data, and will get serialized as equivalent base64-encoded String value

Annotations
@Override
binaryNodeback to summary
public BinaryNode binaryNode(byte[] data, int offset, int length)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.binaryNode.

Factory method for constructing a node that represents given binary data, and will get serialized as equivalent base64-encoded String value

Annotations
@Override
booleanNodeback to summary
public BooleanNode booleanNode(boolean v)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.booleanNode.

Factory method for getting an instance of JSON boolean value (either literal 'true' or 'false')

Annotations
@Override
getMaxElementIndexForInsertback to summary
public int getMaxElementIndexForInsert()
Since
2.14
missingNodeback to summary
public JsonNode missingNode()
nullNodeback to summary
public NullNode nullNode()

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.nullNode.

Factory method for getting an instance of JSON null node (which represents literal null value)

Annotations
@Override
numberNodeback to summary
public NumericNode numberNode(byte v)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Factory method for getting an instance of JSON numeric value that expresses given 8-bit value

Annotations
@Override
numberNodeback to summary
public ValueNode numberNode(Byte value)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Alternate factory method that will handle wrapper value, which may be null. Due to possibility of null, returning type is not guaranteed to be NumericNode, but just ValueNode.

Annotations
@Override
numberNodeback to summary
public NumericNode numberNode(short v)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Factory method for getting an instance of JSON numeric value that expresses given 16-bit integer value

Annotations
@Override
numberNodeback to summary
public ValueNode numberNode(Short value)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Alternate factory method that will handle wrapper value, which may be null. Due to possibility of null, returning type is not guaranteed to be NumericNode, but just ValueNode.

Annotations
@Override
numberNodeback to summary
public NumericNode numberNode(int v)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Factory method for getting an instance of JSON numeric value that expresses given 32-bit integer value

Annotations
@Override
numberNodeback to summary
public ValueNode numberNode(Integer value)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Alternate factory method that will handle wrapper value, which may be null. Due to possibility of null, returning type is not guaranteed to be NumericNode, but just ValueNode.

Annotations
@Override
numberNodeback to summary
public NumericNode numberNode(long v)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Factory method for getting an instance of JSON numeric value that expresses given 64-bit integer value

Annotations
@Override
numberNodeback to summary
public ValueNode numberNode(Long v)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Alternate factory method that will handle wrapper value, which may be null. Due to possibility of null, returning type is not guaranteed to be NumericNode, but just ValueNode.

Annotations
@Override
numberNodeback to summary
public ValueNode numberNode(BigInteger v)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Factory method for getting an instance of JSON numeric value that expresses given unlimited range integer value

Annotations
@Override
numberNodeback to summary
public NumericNode numberNode(float v)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Factory method for getting an instance of JSON numeric value that expresses given 32-bit floating point value

Annotations
@Override
numberNodeback to summary
public ValueNode numberNode(Float value)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Alternate factory method that will handle wrapper value, which may be null. Due to possibility of null, returning type is not guaranteed to be NumericNode, but just ValueNode.

Annotations
@Override
numberNodeback to summary
public NumericNode numberNode(double v)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Factory method for getting an instance of JSON numeric value that expresses given 64-bit floating point value

Annotations
@Override
numberNodeback to summary
public ValueNode numberNode(Double value)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Alternate factory method that will handle wrapper value, which may be null. Due to possibility of null, returning type is not guaranteed to be NumericNode, but just ValueNode.

Annotations
@Override
numberNodeback to summary
public ValueNode numberNode(BigDecimal v)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.numberNode.

Factory method for getting an instance of JSON numeric value that expresses given unlimited precision floating point value

Note that regardless whether the factory has been built to normalize decimal values (see class JavaDoc), the BigDecimal argument will NOT be modified by this method -- caller will need to handle normalization, if any.

Annotations
@Override
See Also
JsonNodeFactory(boolean)
objectNodeback to summary
public ObjectNode objectNode()

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.objectNode.

Factory method for constructing an empty JSON Object ("struct") node

Annotations
@Override
pojoNodeback to summary
public ValueNode pojoNode(Object pojo)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.pojoNode.

Factory method for constructing a wrapper for POJO ("Plain Old Java Object") objects; these will get serialized using data binding, usually as JSON Objects, but in some cases as JSON Strings or other node types.

Annotations
@Override
rawValueNodeback to summary
public ValueNode rawValueNode(RawValue value)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.rawValueNode.

Doc from com.fasterxml.jackson.databind.node.JsonNodeCreator.rawValueNode.

Factory method to use for adding "raw values"; pre-encoded values that are included exactly as-is when node is serialized. This may be used, for example, to include fully serialized JSON sub-trees. Note that the concept may not work with all backends, and since no translation of any kinds is done it will not work when converting between data formats.

Annotations
@Override
textNodeback to summary
public TextNode textNode(String text)

Implements com.fasterxml.jackson.databind.node.JsonNodeCreator.textNode.

Factory method for constructing a node that represents JSON String value

Annotations
@Override
willStripTrailingBigDecimalZeroesback to summary
public boolean willStripTrailingBigDecimalZeroes()

Accessor needed by JsonNodeDeserializer.

Since
2.15
withExactBigDecimalsback to summary
public static JsonNodeFactory withExactBigDecimals(boolean bigDecimalExact)

Return a factory instance with the desired behavior for BigDecimals

See JsonNodeFactory(boolean) for a full description.

Parameters
bigDecimalExact:boolean

If {code true} DISABLE normalization of BigDecimal values; if {code false} ENABLE normalization

Returns:JsonNodeFactory

a factory instance with specified configuration

Annotations
@Deprecated