Class JsonNodeFactory
- java.lang.Object
-
- com.fasterxml.jackson.databind.node.JsonNodeFactory
-
- All Implemented Interfaces:
JsonNodeCreator,java.io.Serializable
public class JsonNodeFactory extends java.lang.Object implements java.io.Serializable, JsonNodeCreator
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
DecimalNodeinstances must be built with exact representations ofBigDecimalinstances; or to use "normalized" instance. This has quite an influence since, for instance, aBigDecimal(and, therefore, aDecimalNode) 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 callingBigDecimal.stripTrailingZeros().Note that configuration of "normalization" changed in 2.15: while
JsonNodeFactorystill has a default setting, the intent is to deprecate and remove this, to be replaced by newJsonNodeFeature.STRIP_TRAILING_BIGDECIMAL_ZEROESsetting. Default setting in 2.15 is to ENABLE normalization: this will likely change at latest in Jackson 3.0 (to leaveBigDecimalvalues as they are). Note, too, that this factory will no longer handle this normalization (if enabled): caller (likeJsonNodeDeserializer) is expected to handle it.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static JsonNodeFactoryinstanceDefault singleton instance that construct "standard" node instances: given that this class is stateless, a globally shared singleton can be used.
-
Constructor Summary
Constructors Constructor Description JsonNodeFactory(boolean bigDecimalExact)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ArrayNodearrayNode()Factory method for constructing an empty JSON Array nodeArrayNodearrayNode(int capacity)Factory method for constructing a JSON Array node with an initial capacityBinaryNodebinaryNode(byte[] data)Factory method for constructing a node that represents given binary data, and will get serialized as equivalent base64-encoded String valueBinaryNodebinaryNode(byte[] data, int offset, int length)Factory method for constructing a node that represents given binary data, and will get serialized as equivalent base64-encoded String valueBooleanNodebooleanNode(boolean v)Factory method for getting an instance of JSON boolean value (either literal 'true' or 'false')intgetMaxElementIndexForInsert()JsonNodemissingNode()NullNodenullNode()Factory method for getting an instance of JSON null node (which represents literal null value)NumericNodenumberNode(byte v)Factory method for getting an instance of JSON numeric value that expresses given 8-bit valueNumericNodenumberNode(double v)Factory method for getting an instance of JSON numeric value that expresses given 64-bit floating point valueNumericNodenumberNode(float v)Factory method for getting an instance of JSON numeric value that expresses given 32-bit floating point valueNumericNodenumberNode(int v)Factory method for getting an instance of JSON numeric value that expresses given 32-bit integer valueNumericNodenumberNode(long v)Factory method for getting an instance of JSON numeric value that expresses given 64-bit integer valueNumericNodenumberNode(short v)Factory method for getting an instance of JSON numeric value that expresses given 16-bit integer valueValueNodenumberNode(java.lang.Byte value)Alternate factory method that will handle wrapper value, which may be null.ValueNodenumberNode(java.lang.Double value)Alternate factory method that will handle wrapper value, which may be null.ValueNodenumberNode(java.lang.Float value)Alternate factory method that will handle wrapper value, which may be null.ValueNodenumberNode(java.lang.Integer value)Alternate factory method that will handle wrapper value, which may be null.ValueNodenumberNode(java.lang.Long v)Alternate factory method that will handle wrapper value, which may be null.ValueNodenumberNode(java.lang.Short value)Alternate factory method that will handle wrapper value, which may be null.ValueNodenumberNode(java.math.BigDecimal v)Factory method for getting an instance of JSON numeric value that expresses given unlimited precision floating point valueValueNodenumberNode(java.math.BigInteger v)Factory method for getting an instance of JSON numeric value that expresses given unlimited range integer valueObjectNodeobjectNode()Factory method for constructing an empty JSON Object ("struct") nodeValueNodepojoNode(java.lang.Object pojo)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.ValueNoderawValueNode(RawValue value)Factory method to use for adding "raw values"; pre-encoded values that are included exactly as-is when node is serialized.TextNodetextNode(java.lang.String text)Factory method for constructing a node that represents JSON String valuebooleanwillStripTrailingBigDecimalZeroes()Accessor needed byJsonNodeDeserializer.static JsonNodeFactorywithExactBigDecimals(boolean bigDecimalExact)Deprecated.UseJsonNodeFeature.STRIP_TRAILING_BIGDECIMAL_ZEROESinstead for configuring behavior.
-
-
-
Field Detail
-
instance
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.
-
-
Method Detail
-
withExactBigDecimals
@Deprecated public static JsonNodeFactory withExactBigDecimals(boolean bigDecimalExact)
Deprecated.UseJsonNodeFeature.STRIP_TRAILING_BIGDECIMAL_ZEROESinstead for configuring behavior.Return a factory instance with the desired behavior for BigDecimalsSee
JsonNodeFactory(boolean)for a full description.- Parameters:
bigDecimalExact- If {code true} DISABLE normalization ofBigDecimalvalues; if {code false} ENABLE normalization- Returns:
- a factory instance with specified configuration
-
getMaxElementIndexForInsert
public int getMaxElementIndexForInsert()
- Since:
- 2.14
-
willStripTrailingBigDecimalZeroes
public boolean willStripTrailingBigDecimalZeroes()
Accessor needed byJsonNodeDeserializer.- Since:
- 2.15
-
booleanNode
public BooleanNode booleanNode(boolean v)
Factory method for getting an instance of JSON boolean value (either literal 'true' or 'false')- Specified by:
booleanNodein interfaceJsonNodeCreator
-
nullNode
public NullNode nullNode()
Factory method for getting an instance of JSON null node (which represents literal null value)- Specified by:
nullNodein interfaceJsonNodeCreator
-
missingNode
public JsonNode missingNode()
-
numberNode
public NumericNode numberNode(byte v)
Factory method for getting an instance of JSON numeric value that expresses given 8-bit value- Specified by:
numberNodein interfaceJsonNodeCreator
-
numberNode
public ValueNode numberNode(java.lang.Byte value)
Alternate factory method that will handle wrapper value, which may be null. Due to possibility of null, returning type is not guaranteed to beNumericNode, but justValueNode.- Specified by:
numberNodein interfaceJsonNodeCreator
-
numberNode
public NumericNode numberNode(short v)
Factory method for getting an instance of JSON numeric value that expresses given 16-bit integer value- Specified by:
numberNodein interfaceJsonNodeCreator
-
numberNode
public ValueNode numberNode(java.lang.Short value)
Alternate factory method that will handle wrapper value, which may be null. Due to possibility of null, returning type is not guaranteed to beNumericNode, but justValueNode.- Specified by:
numberNodein interfaceJsonNodeCreator
-
numberNode
public NumericNode numberNode(int v)
Factory method for getting an instance of JSON numeric value that expresses given 32-bit integer value- Specified by:
numberNodein interfaceJsonNodeCreator
-
numberNode
public ValueNode numberNode(java.lang.Integer value)
Alternate factory method that will handle wrapper value, which may be null. Due to possibility of null, returning type is not guaranteed to beNumericNode, but justValueNode.- Specified by:
numberNodein interfaceJsonNodeCreator
-
numberNode
public NumericNode numberNode(long v)
Factory method for getting an instance of JSON numeric value that expresses given 64-bit integer value- Specified by:
numberNodein interfaceJsonNodeCreator
-
numberNode
public ValueNode numberNode(java.lang.Long v)
Alternate factory method that will handle wrapper value, which may be null. Due to possibility of null, returning type is not guaranteed to beNumericNode, but justValueNode.- Specified by:
numberNodein interfaceJsonNodeCreator
-
numberNode
public ValueNode numberNode(java.math.BigInteger v)
Factory method for getting an instance of JSON numeric value that expresses given unlimited range integer value- Specified by:
numberNodein interfaceJsonNodeCreator
-
numberNode
public NumericNode numberNode(float v)
Factory method for getting an instance of JSON numeric value that expresses given 32-bit floating point value- Specified by:
numberNodein interfaceJsonNodeCreator
-
numberNode
public ValueNode numberNode(java.lang.Float value)
Alternate factory method that will handle wrapper value, which may be null. Due to possibility of null, returning type is not guaranteed to beNumericNode, but justValueNode.- Specified by:
numberNodein interfaceJsonNodeCreator
-
numberNode
public NumericNode numberNode(double v)
Factory method for getting an instance of JSON numeric value that expresses given 64-bit floating point value- Specified by:
numberNodein interfaceJsonNodeCreator
-
numberNode
public ValueNode numberNode(java.lang.Double value)
Alternate factory method that will handle wrapper value, which may be null. Due to possibility of null, returning type is not guaranteed to beNumericNode, but justValueNode.- Specified by:
numberNodein interfaceJsonNodeCreator
-
numberNode
public ValueNode numberNode(java.math.BigDecimal v)
Factory method for getting an instance of JSON numeric value that expresses given unlimited precision floating point valueNote that regardless whether the factory has been built to normalize decimal values (see class JavaDoc), the
BigDecimalargument will NOT be modified by this method -- caller will need to handle normalization, if any.- Specified by:
numberNodein interfaceJsonNodeCreator- See Also:
JsonNodeFactory(boolean)
-
textNode
public TextNode textNode(java.lang.String text)
Factory method for constructing a node that represents JSON String value- Specified by:
textNodein interfaceJsonNodeCreator
-
binaryNode
public BinaryNode binaryNode(byte[] data)
Factory method for constructing a node that represents given binary data, and will get serialized as equivalent base64-encoded String value- Specified by:
binaryNodein interfaceJsonNodeCreator
-
binaryNode
public BinaryNode binaryNode(byte[] data, int offset, int length)
Factory method for constructing a node that represents given binary data, and will get serialized as equivalent base64-encoded String value- Specified by:
binaryNodein interfaceJsonNodeCreator
-
arrayNode
public ArrayNode arrayNode()
Factory method for constructing an empty JSON Array node- Specified by:
arrayNodein interfaceJsonNodeCreator
-
arrayNode
public ArrayNode arrayNode(int capacity)
Factory method for constructing a JSON Array node with an initial capacity- Specified by:
arrayNodein interfaceJsonNodeCreator- Since:
- 2.8
-
objectNode
public ObjectNode objectNode()
Factory method for constructing an empty JSON Object ("struct") node- Specified by:
objectNodein interfaceJsonNodeCreator
-
pojoNode
public ValueNode pojoNode(java.lang.Object pojo)
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.- Specified by:
pojoNodein interfaceJsonNodeCreator
-
rawValueNode
public ValueNode rawValueNode(RawValue value)
Description copied from interface:JsonNodeCreatorFactory 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.- Specified by:
rawValueNodein interfaceJsonNodeCreator
-
-