Class JsonNodeFactory
- All Implemented Interfaces:
JsonNodeCreator,Serializable
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 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 JsonNodeDeserializer)
is expected to handle it.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final JsonNodeFactoryDefault singleton instance that construct "standard" node instances: given that this class is stateless, a globally shared singleton can be used.protected static final intConstant that defines maximumJsonPointerelement index we use for inserts. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefault constructor.JsonNodeFactory(boolean bigDecimalExact) -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean_inIntRange(long l) Factory method for constructing an empty JSON Array nodearrayNode(int capacity) Factory method for constructing a JSON Array node with an initial capacitybinaryNode(byte[] data) Factory method for constructing a node that represents given binary data, and will get serialized as equivalent base64-encoded String valuebinaryNode(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 valuebooleanNode(boolean v) Factory method for getting an instance of JSON boolean value (either literal 'true' or 'false')intnullNode()Factory method for getting an instance of JSON null node (which represents literal null value)numberNode(byte v) Factory method for getting an instance of JSON numeric value that expresses given 8-bit valuenumberNode(double v) Factory method for getting an instance of JSON numeric value that expresses given 64-bit floating point valuenumberNode(float v) Factory method for getting an instance of JSON numeric value that expresses given 32-bit floating point valuenumberNode(int v) Factory method for getting an instance of JSON numeric value that expresses given 32-bit integer valuenumberNode(long v) Factory method for getting an instance of JSON numeric value that expresses given 64-bit integer valuenumberNode(short v) Factory method for getting an instance of JSON numeric value that expresses given 16-bit integer valuenumberNode(Byte value) Alternate factory method that will handle wrapper value, which may be null.numberNode(Double value) Alternate factory method that will handle wrapper value, which may be null.numberNode(Float value) Alternate factory method that will handle wrapper value, which may be null.numberNode(Integer value) Alternate factory method that will handle wrapper value, which may be null.numberNode(Long v) Alternate factory method that will handle wrapper value, which may be null.numberNode(Short value) Alternate factory method that will handle wrapper value, which may be null.Factory method for getting an instance of JSON numeric value that expresses given unlimited precision floating point valueFactory method for getting an instance of JSON numeric value that expresses given unlimited range integer valueFactory method for constructing an empty JSON Object ("struct") nodeFactory 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.rawValueNode(RawValue value) Factory method to use for adding "raw values"; pre-encoded values that are included exactly as-is when node is serialized.Factory method for constructing a node that represents JSON String valuebooleanAccessor needed byJsonNodeDeserializer.static JsonNodeFactorywithExactBigDecimals(boolean bigDecimalExact) Deprecated.
-
Field Details
-
MAX_ELEMENT_INDEX_FOR_INSERT
protected static final int MAX_ELEMENT_INDEX_FOR_INSERTConstant that defines maximumJsonPointerelement index we use for inserts.- See Also:
-
instance
Default singleton instance that construct "standard" node instances: given that this class is stateless, a globally shared singleton can be used.
-
-
Constructor Details
-
JsonNodeFactory
public JsonNodeFactory(boolean bigDecimalExact) - Parameters:
bigDecimalExact- see Class description on "BigDecimal normalization"- See Also:
-
JsonNodeFactory
protected JsonNodeFactory()Default constructor.This calls
JsonNodeFactory(boolean)withfalseas an argument.
-
-
Method Details
-
withExactBigDecimals
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
Factory method for getting an instance of JSON boolean value (either literal 'true' or 'false')- Specified by:
booleanNodein interfaceJsonNodeCreator
-
nullNode
Factory method for getting an instance of JSON null node (which represents literal null value)- Specified by:
nullNodein interfaceJsonNodeCreator
-
missingNode
-
numberNode
Factory method for getting an instance of JSON numeric value that expresses given 8-bit value- Specified by:
numberNodein interfaceJsonNodeCreator
-
numberNode
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
Factory method for getting an instance of JSON numeric value that expresses given 16-bit integer value- Specified by:
numberNodein interfaceJsonNodeCreator
-
numberNode
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
Factory method for getting an instance of JSON numeric value that expresses given 32-bit integer value- Specified by:
numberNodein interfaceJsonNodeCreator
-
numberNode
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
Factory method for getting an instance of JSON numeric value that expresses given 64-bit integer value- Specified by:
numberNodein interfaceJsonNodeCreator
-
numberNode
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
Factory method for getting an instance of JSON numeric value that expresses given unlimited range integer value- Specified by:
numberNodein interfaceJsonNodeCreator
-
numberNode
Factory method for getting an instance of JSON numeric value that expresses given 32-bit floating point value- Specified by:
numberNodein interfaceJsonNodeCreator
-
numberNode
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
Factory method for getting an instance of JSON numeric value that expresses given 64-bit floating point value- Specified by:
numberNodein interfaceJsonNodeCreator
-
numberNode
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
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:
-
textNode
Factory method for constructing a node that represents JSON String value- Specified by:
textNodein interfaceJsonNodeCreator
-
binaryNode
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
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
Factory method for constructing an empty JSON Array node- Specified by:
arrayNodein interfaceJsonNodeCreator
-
arrayNode
Factory method for constructing a JSON Array node with an initial capacity- Specified by:
arrayNodein interfaceJsonNodeCreator- Since:
- 2.8
-
objectNode
Factory method for constructing an empty JSON Object ("struct") node- Specified by:
objectNodein interfaceJsonNodeCreator
-
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.- Specified by:
pojoNodein interfaceJsonNodeCreator
-
rawValueNode
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
-
_inIntRange
protected boolean _inIntRange(long l)
-
JsonNodeFeature.STRIP_TRAILING_BIGDECIMAL_ZEROESinstead for configuring behavior.