Top Description Fields Constructors Methods
tools.jackson.databind.node

public Class POJONode

extends ValueNode
Class Inheritance
Imports
java.math.BigDecimal, .BigInteger, java.util.Objects, .Optional, .OptionalDouble, .OptionalInt, .OptionalLong, tools.jackson.core.*, tools.jackson.databind.JacksonSerializable, .SerializationContext, tools.jackson.databind.util.ClassUtil

Value node that contains a wrapped POJO, to be serialized as a JSON constructed through data mapping (usually done by calling tools.jackson.databind.ObjectMapper).

Field Summary

Modifier and TypeField and Description
protected final Object
private static final long
Inherited from tools.jackson.databind.node.ValueNode:
BD_MAX_INTEGERBD_MAX_LONGBD_MAX_SHORTBD_MIN_INTEGERBD_MIN_LONGBD_MIN_SHORTBI_MAX_INTEGERBI_MAX_LONGBI_MAX_SHORTBI_MIN_INTEGERBI_MIN_LONGBI_MIN_SHORTMISSING

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected Boolean
_asBoolean()

Overrides tools.jackson.databind.node.BaseJsonNode._asBoolean.

Method sub-classes should override if they can produce boolean values via asBoolean() -- if not, return null (in which case appropriate error will be thrown or default value returned).

protected String
_asString()

Overrides tools.jackson.databind.node.BaseJsonNode._asString.

Method sub-classes should override if they can produce String values via asString() -- if not, return null (in which case appropriate error will be thrown or default value returned).

protected BigDecimal
protected BigInteger
protected Double
protected Float
protected Long
protected boolean
protected String
_valueDesc()

Implements abstract tools.jackson.databind.node.BaseJsonNode._valueDesc.

Method for implementation classes to return a short description of contained value, to be used in error messages.

public BigInteger
asBigInteger()

Overrides tools.jackson.databind.node.BaseJsonNode.asBigInteger.

Method similar to bigIntegerValue() but in addition to coercing Number values (same as bigIntegerValue()), will also try to coerce a couple of additional types (or cases):

  • JSON Floating-point numbers with fractions (ones without fractions are ok for bigIntegerValue()) will be truncated to integer value (like with BigDecimal#toBigInteger()))
  • JSON Strings that represent JSON Numbers ("stringified" numbers)
  • JSON Null (converted to 0))
  • POJO nodes that contain Number values
public BigInteger
asBigInteger(BigInteger defaultValue)

Overrides tools.jackson.databind.node.BaseJsonNode.asBigInteger.

Method similar to asBigInteger(), but that will return specified defaultValue if this node cannot be converted to BigInteger.

public Optional<BigInteger>
asBigIntegerOpt()

Overrides tools.jackson.databind.node.BaseJsonNode.asBigIntegerOpt.

Method similar to bigIntegerValue(), but that will return empty (Optional.empty()) if this node cannot be converted to Java BigInteger.

public BigDecimal
asDecimal()

Overrides tools.jackson.databind.node.BaseJsonNode.asDecimal.

Method that will try to access value of this node as a BigDecimal: but if node value cannot be expressed exactly as a BigDecimal, a JsonNodeException will be thrown.

public BigDecimal
asDecimal(BigDecimal defaultValue)

Overrides tools.jackson.databind.node.BaseJsonNode.asDecimal.

Method similar to asDecimal(), but that will return defaultValue if this node cannot be coerced to Java BigDecimal.

public Optional<BigDecimal>
asDecimalOpt()

Overrides tools.jackson.databind.node.BaseJsonNode.asDecimalOpt.

Method similar to asDecimal(), but that will return empty Optional (Optional.empty()) if this node cannot be coerced to BigDecimal.

public double
asDouble()

Overrides tools.jackson.databind.node.BaseJsonNode.asDouble.

Method similar to doubleValue() but in addition to coercing Number values will also try coerce couple of additional types:

  • JSON String that represents JSON Numbers ("stringified" numbers)
  • JSON Null (converted to 0.0d)
  • POJO nodes that contain Number values
public double
asDouble(double defaultValue)

Overrides tools.jackson.databind.node.BaseJsonNode.asDouble.

Method similar to asDouble(), but that will return defaultValue if this node cannot be coerced to double.

public OptionalDouble
asDoubleOpt()

Overrides tools.jackson.databind.node.BaseJsonNode.asDoubleOpt.

Method similar to asDouble(), but that will return (OptionalDouble.empty()) if this node cannot be coerced to double.

public float
asFloat()

Overrides tools.jackson.databind.node.BaseJsonNode.asFloat.

Method similar to floatValue() but in addition to coercing Number values will also try coerce couple of additional types:

  • JSON String that represents JSON Numbers ("stringified" numbers)
  • JSON Null (converted to 0.0f)
  • POJO nodes that contain Number values
public float
asFloat(float defaultValue)

Overrides tools.jackson.databind.node.BaseJsonNode.asFloat.

Method similar to asFloat(), but that will return defaultValue if this node cannot be coerced to float.

public Optional<Float>
asFloatOpt()

Overrides tools.jackson.databind.node.BaseJsonNode.asFloatOpt.

Method similar to asFloat(), but that will return (Optional.empty()) if this node cannot be coerced to float.

public int
asInt()

Overrides tools.jackson.databind.node.BaseJsonNode.asInt.

Method similar to intValue() but in addition to coercing Number values (same as intValue()), will also try to coerce a couple of additional types (or cases):

  • JSON Floating-point numbers with fractions (ones without fractions are ok for intValue()) will be truncated to int (if (and only if) they fit in int range).
  • JSON Strings that represent JSON Numbers ("stringified" numbers)
  • JSON Null (converted to 0))
  • POJO nodes that contain Number values
public int
asInt(int defaultValue)

Overrides tools.jackson.databind.node.BaseJsonNode.asInt.

Method similar to intValue(), but that will return specified defaultValue if this node cannot be converted to int.

public OptionalInt
asIntOpt()

Overrides tools.jackson.databind.node.BaseJsonNode.asIntOpt.

Method similar to asInt(), but that will return (OptionalInt.empty()) if this node cannot be coerced to int.

public long
asLong()

Overrides tools.jackson.databind.node.BaseJsonNode.asLong.

Method similar to longValue() but in addition to coercing Number values (same as longValue()), will also try to coerce a couple of additional types (or cases):

  • JSON Floating-point numbers with fractions (ones without fractions are ok for longValue()) will be truncated to long (if (and only if) they fit in long range).
  • JSON Strings that represent JSON Numbers ("stringified" numbers)
  • JSON Null (converted to 0))
  • POJO nodes that contain Number values
public long
asLong(long defaultValue)

Overrides tools.jackson.databind.node.BaseJsonNode.asLong.

Method similar to asLong(), but that will return specified defaultValue if this node cannot be coerced to long (instead of throwing an exception).

public OptionalLong
asLongOpt()

Overrides tools.jackson.databind.node.BaseJsonNode.asLongOpt.

Method similar to asLong(), but that will return (OptionalLong.empty()) if this node cannot be coerced to long.

public short
asShort()

Overrides tools.jackson.databind.node.BaseJsonNode.asShort.

Method similar to shortValue() but in addition to coercing Number values (same as shortValue()), will also try to coerce a couple of additional types (or cases):

  • JSON Floating-point numbers with fractions (ones without fractions are ok for shortValue()) will be truncated to short (if (and only if) they fit in short range).
  • JSON Strings that represent JSON Numbers ("stringified" numbers)
  • JSON Null (converted to 0))
  • POJO nodes that contain Number values
public short
asShort(short defaultValue)

Overrides tools.jackson.databind.node.BaseJsonNode.asShort.

Method similar to shortValue(), but that will return specified defaultValue if this node cannot be converted to short.

public Optional<Short>
asShortOpt()

Overrides tools.jackson.databind.node.BaseJsonNode.asShortOpt.

Method similar to asShort(), but that will return (Optional.empty()) if this node cannot be coerced to short.

public JsonToken
asToken()

Implements abstract tools.jackson.databind.node.ValueNode.asToken.

Implements tools.jackson.core.TreeNode.asToken.

Method that can be used for efficient type detection when using stream abstraction for traversing nodes.

public byte[]
binaryValue()

Overrides tools.jackson.databind.node.BaseJsonNode.binaryValue.

As it is possible that some implementations embed byte[] as POJONode (despite optimal being BinaryNode), let's add support for exposing binary data here too.

public boolean
equals(Object o)

Implements abstract tools.jackson.databind.JsonNode.equals.

Equality for node objects is defined as full (deep) value equality.

public JsonNodeType
getNodeType()

Implements abstract tools.jackson.databind.JsonNode.getNodeType.

Return the type of this node

public Object
getPojo()

Method that can be used to access the POJO this node wraps.

public int
hashCode()

Implements abstract tools.jackson.databind.node.BaseJsonNode.hashCode.

Returns a hash code value for this object.

public boolean
isEmbeddedValue()

Overrides tools.jackson.databind.node.BaseJsonNode.isEmbeddedValue.

Implements tools.jackson.core.TreeNode.isEmbeddedValue.

Method that returns true if this node represents an embedded "foreign" (or perhaps native?) object (like POJO), not represented as regular content.

public final void
serialize(JsonGenerator gen, SerializationContext ctxt)

Implements abstract tools.jackson.databind.node.BaseJsonNode.serialize.

Implements tools.jackson.databind.JacksonSerializable.serialize.

Method called to serialize node instances using given generator.

Inherited from tools.jackson.databind.node.ValueNode:
_atdeepCopyfindParentfindParentsfindValuefindValuesfindValuesAsStringgetgethashashasNonNullhasNonNullisEmptypathpathserializeWithType

Field Detail

_valueback to summary
protected final Object _value
serialVersionUIDback to summary
private static final long serialVersionUID

Hides tools.jackson.databind.node.ValueNode.serialVersionUID.

Constructor Detail

POJONodeback to summary
public POJONode(Object v)

Method Detail

_asBooleanback to summary
protected Boolean _asBoolean()

Overrides tools.jackson.databind.node.BaseJsonNode._asBoolean.

Doc from tools.jackson.databind.node.BaseJsonNode._asBoolean.

Method sub-classes should override if they can produce boolean values via asBoolean() -- if not, return null (in which case appropriate error will be thrown or default value returned).

Annotations
@Override
_asStringback to summary
protected String _asString()

Overrides tools.jackson.databind.node.BaseJsonNode._asString.

Doc from tools.jackson.databind.node.BaseJsonNode._asString.

Method sub-classes should override if they can produce String values via asString() -- if not, return null (in which case appropriate error will be thrown or default value returned).

Annotations
@Override
_extractAsBigDecimalback to summary
protected BigDecimal _extractAsBigDecimal()
_extractAsBigIntegerback to summary
protected BigInteger _extractAsBigInteger()
_extractAsDoubleback to summary
protected Double _extractAsDouble()
_extractAsFloatback to summary
protected Float _extractAsFloat()
_extractAsLongback to summary
protected Long _extractAsLong()
_pojoEqualsback to summary
protected boolean _pojoEquals(POJONode other)
_valueDescback to summary
protected String _valueDesc()

Implements abstract tools.jackson.databind.node.BaseJsonNode._valueDesc.

Doc from tools.jackson.databind.node.BaseJsonNode._valueDesc.

Method for implementation classes to return a short description of contained value, to be used in error messages.

Annotations
@Override
asBigIntegerback to summary
public BigInteger asBigInteger()

Overrides tools.jackson.databind.node.BaseJsonNode.asBigInteger.

Doc from tools.jackson.databind.JsonNode.asBigInteger.

Method similar to bigIntegerValue() but in addition to coercing Number values (same as bigIntegerValue()), will also try to coerce a couple of additional types (or cases):

  • JSON Floating-point numbers with fractions (ones without fractions are ok for bigIntegerValue()) will be truncated to integer value (like with BigDecimal#toBigInteger()))
  • JSON Strings that represent JSON Numbers ("stringified" numbers)
  • JSON Null (converted to 0))
  • POJO nodes that contain Number values
Annotations
@Override
asBigIntegerback to summary
public BigInteger asBigInteger(BigInteger defaultValue)

Overrides tools.jackson.databind.node.BaseJsonNode.asBigInteger.

Doc from tools.jackson.databind.JsonNode.asBigInteger.

Method similar to asBigInteger(), but that will return specified defaultValue if this node cannot be converted to BigInteger.

Annotations
@Override
asBigIntegerOptback to summary
public Optional<BigInteger> asBigIntegerOpt()

Overrides tools.jackson.databind.node.BaseJsonNode.asBigIntegerOpt.

Doc from tools.jackson.databind.JsonNode.asBigIntegerOpt.

Method similar to bigIntegerValue(), but that will return empty (Optional.empty()) if this node cannot be converted to Java BigInteger.

Annotations
@Override
asDecimalback to summary
public BigDecimal asDecimal()

Overrides tools.jackson.databind.node.BaseJsonNode.asDecimal.

Doc from tools.jackson.databind.JsonNode.asDecimal.

Method that will try to access value of this node as a BigDecimal: but if node value cannot be expressed exactly as a BigDecimal, a JsonNodeException will be thrown. Access works for following cases:

  • JSON Floating-point values (but not "NaN" or "Infinity")
  • JSON Integer values
  • JSON String that represents JSON Numbers ("stringified" numbers)
  • JSON Null (converted to BigDecimal#ZERO))
  • POJO nodes that contain Number values

Annotations
@Override
asDecimalback to summary
public BigDecimal asDecimal(BigDecimal defaultValue)

Overrides tools.jackson.databind.node.BaseJsonNode.asDecimal.

Doc from tools.jackson.databind.JsonNode.asDecimal.

Method similar to asDecimal(), but that will return defaultValue if this node cannot be coerced to Java BigDecimal.

Annotations
@Override
asDecimalOptback to summary
public Optional<BigDecimal> asDecimalOpt()

Overrides tools.jackson.databind.node.BaseJsonNode.asDecimalOpt.

Doc from tools.jackson.databind.JsonNode.asDecimalOpt.

Method similar to asDecimal(), but that will return empty Optional (Optional.empty()) if this node cannot be coerced to BigDecimal.

Annotations
@Override
asDoubleback to summary
public double asDouble()

Overrides tools.jackson.databind.node.BaseJsonNode.asDouble.

Doc from tools.jackson.databind.JsonNode.asDouble.

Method similar to doubleValue() but in addition to coercing Number values will also try coerce couple of additional types:

  • JSON String that represents JSON Numbers ("stringified" numbers)
  • JSON Null (converted to 0.0d)
  • POJO nodes that contain Number values

Annotations
@Override
asDoubleback to summary
public double asDouble(double defaultValue)

Overrides tools.jackson.databind.node.BaseJsonNode.asDouble.

Doc from tools.jackson.databind.JsonNode.asDouble.

Method similar to asDouble(), but that will return defaultValue if this node cannot be coerced to double.

Annotations
@Override
asDoubleOptback to summary
public OptionalDouble asDoubleOpt()

Overrides tools.jackson.databind.node.BaseJsonNode.asDoubleOpt.

Doc from tools.jackson.databind.JsonNode.asDoubleOpt.

Method similar to asDouble(), but that will return (OptionalDouble.empty()) if this node cannot be coerced to double.

Annotations
@Override
asFloatback to summary
public float asFloat()

Overrides tools.jackson.databind.node.BaseJsonNode.asFloat.

Doc from tools.jackson.databind.JsonNode.asFloat.

Method similar to floatValue() but in addition to coercing Number values will also try coerce couple of additional types:

  • JSON String that represents JSON Numbers ("stringified" numbers)
  • JSON Null (converted to 0.0f)
  • POJO nodes that contain Number values

Annotations
@Override
asFloatback to summary
public float asFloat(float defaultValue)

Overrides tools.jackson.databind.node.BaseJsonNode.asFloat.

Doc from tools.jackson.databind.JsonNode.asFloat.

Method similar to asFloat(), but that will return defaultValue if this node cannot be coerced to float.

Annotations
@Override
asFloatOptback to summary
public Optional<Float> asFloatOpt()

Overrides tools.jackson.databind.node.BaseJsonNode.asFloatOpt.

Doc from tools.jackson.databind.JsonNode.asFloatOpt.

Method similar to asFloat(), but that will return (Optional.empty()) if this node cannot be coerced to float.

Annotations
@Override
asIntback to summary
public int asInt()

Overrides tools.jackson.databind.node.BaseJsonNode.asInt.

Doc from tools.jackson.databind.JsonNode.asInt.

Method similar to intValue() but in addition to coercing Number values (same as intValue()), will also try to coerce a couple of additional types (or cases):

  • JSON Floating-point numbers with fractions (ones without fractions are ok for intValue()) will be truncated to int (if (and only if) they fit in int range).
  • JSON Strings that represent JSON Numbers ("stringified" numbers)
  • JSON Null (converted to 0))
  • POJO nodes that contain Number values
Annotations
@Override
asIntback to summary
public int asInt(int defaultValue)

Overrides tools.jackson.databind.node.BaseJsonNode.asInt.

Doc from tools.jackson.databind.JsonNode.asInt.

Method similar to intValue(), but that will return specified defaultValue if this node cannot be converted to int.

Annotations
@Override
asIntOptback to summary
public OptionalInt asIntOpt()

Overrides tools.jackson.databind.node.BaseJsonNode.asIntOpt.

Doc from tools.jackson.databind.JsonNode.asIntOpt.

Method similar to asInt(), but that will return (OptionalInt.empty()) if this node cannot be coerced to int.

Annotations
@Override
asLongback to summary
public long asLong()

Overrides tools.jackson.databind.node.BaseJsonNode.asLong.

Doc from tools.jackson.databind.JsonNode.asLong.

Method similar to longValue() but in addition to coercing Number values (same as longValue()), will also try to coerce a couple of additional types (or cases):

  • JSON Floating-point numbers with fractions (ones without fractions are ok for longValue()) will be truncated to long (if (and only if) they fit in long range).
  • JSON Strings that represent JSON Numbers ("stringified" numbers)
  • JSON Null (converted to 0))
  • POJO nodes that contain Number values
Annotations
@Override
asLongback to summary
public long asLong(long defaultValue)

Overrides tools.jackson.databind.node.BaseJsonNode.asLong.

Doc from tools.jackson.databind.JsonNode.asLong.

Method similar to asLong(), but that will return specified defaultValue if this node cannot be coerced to long (instead of throwing an exception).

Annotations
@Override
asLongOptback to summary
public OptionalLong asLongOpt()

Overrides tools.jackson.databind.node.BaseJsonNode.asLongOpt.

Doc from tools.jackson.databind.JsonNode.asLongOpt.

Method similar to asLong(), but that will return (OptionalLong.empty()) if this node cannot be coerced to long.

Annotations
@Override
asShortback to summary
public short asShort()

Overrides tools.jackson.databind.node.BaseJsonNode.asShort.

Doc from tools.jackson.databind.JsonNode.asShort.

Method similar to shortValue() but in addition to coercing Number values (same as shortValue()), will also try to coerce a couple of additional types (or cases):

  • JSON Floating-point numbers with fractions (ones without fractions are ok for shortValue()) will be truncated to short (if (and only if) they fit in short range).
  • JSON Strings that represent JSON Numbers ("stringified" numbers)
  • JSON Null (converted to 0))
  • POJO nodes that contain Number values
Annotations
@Override
asShortback to summary
public short asShort(short defaultValue)

Overrides tools.jackson.databind.node.BaseJsonNode.asShort.

Doc from tools.jackson.databind.JsonNode.asShort.

Method similar to shortValue(), but that will return specified defaultValue if this node cannot be converted to short.

Annotations
@Override
asShortOptback to summary
public Optional<Short> asShortOpt()

Overrides tools.jackson.databind.node.BaseJsonNode.asShortOpt.

Doc from tools.jackson.databind.JsonNode.asShortOpt.

Method similar to asShort(), but that will return (Optional.empty()) if this node cannot be coerced to short.

Annotations
@Override
asTokenback to summary
public JsonToken asToken()

Implements abstract tools.jackson.databind.node.ValueNode.asToken.

Implements tools.jackson.core.TreeNode.asToken.

Doc from tools.jackson.databind.node.BaseJsonNode.asToken.

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)

Annotations
@Override
binaryValueback to summary
public byte[] binaryValue()

Overrides tools.jackson.databind.node.BaseJsonNode.binaryValue.

As it is possible that some implementations embed byte[] as POJONode (despite optimal being BinaryNode), let's add support for exposing binary data here too.

Annotations
@Override
equalsback to summary
public boolean equals(Object o)

Implements abstract tools.jackson.databind.JsonNode.equals.

Doc from tools.jackson.databind.JsonNode.equals.

Equality for node objects is defined as full (deep) value equality. This means that it is possible to compare complete JSON trees for equality by comparing equality of root nodes.

Note

marked as abstract to ensure all implementation classes define it properly and not rely on definition from java.lang.Object.

Annotations
@Override
getNodeTypeback to summary
public JsonNodeType getNodeType()

Implements abstract tools.jackson.databind.JsonNode.getNodeType.

Doc from tools.jackson.databind.JsonNode.getNodeType.

Return the type of this node

Annotations
@Override
getPojoback to summary
public Object getPojo()

Method that can be used to access the POJO this node wraps.

hashCodeback to summary
public int hashCode()

Implements abstract tools.jackson.databind.node.BaseJsonNode.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
isEmbeddedValueback to summary
public boolean isEmbeddedValue()

Overrides tools.jackson.databind.node.BaseJsonNode.isEmbeddedValue.

Implements tools.jackson.core.TreeNode.isEmbeddedValue.

Doc from tools.jackson.core.TreeNode.isEmbeddedValue.

Method that returns true if this node represents an embedded "foreign" (or perhaps native?) object (like POJO), not represented as regular content. Such nodes are used to pass information that either native format cannot express as-is, metadata not included within at all, or something else that requires special handling.

Annotations
@Override
serializeback to summary
public final void serialize(JsonGenerator gen, SerializationContext ctxt) throws JacksonException

Implements abstract tools.jackson.databind.node.BaseJsonNode.serialize.

Implements tools.jackson.databind.JacksonSerializable.serialize.

Doc from tools.jackson.databind.node.BaseJsonNode.serialize.

Method called to serialize node instances using given generator.

Annotations
@Override