public final class NumberNode extends NumericNode
NumericNode and derivates
This class is a wrapper over all NumericNode instances and
overrides Object.equals(Object) and Object.hashCode(), all
the while retaining all other characteristics of the underlying node.
The reason for this is to allow for mathematical numeric equality: with
JSON Schema, 1 and 1.0, for instance, are equal, but they are
not of the same type.
NO_NODES, NO_STRINGS| Constructor and Description |
|---|
NumberNode(JsonNode node)
Sole constructor
|
| Modifier and Type | Method and Description |
|---|---|
String |
asText() |
JsonToken |
asToken() |
BigInteger |
bigIntegerValue() |
boolean |
canConvertToInt() |
boolean |
canConvertToLong() |
BigDecimal |
decimalValue() |
double |
doubleValue() |
boolean |
equals(Object o) |
int |
hashCode() |
int |
intValue() |
long |
longValue() |
JsonParser.NumberType |
numberType() |
Number |
numberValue() |
void |
serialize(JsonGenerator jgen,
SerializerProvider provider) |
String |
toString() |
asDouble, asDouble, asInt, asInt, asLong, asLong, isNumberdeepCopy, isValueNode, path, path, serializeWithTypefindParent, findParents, findPath, findValue, findValues, findValuesAsText, traverseasBoolean, asBoolean, binaryValue, booleanValue, elements, fieldNames, fields, findParents, findValues, findValuesAsText, get, get, has, has, hasNonNull, hasNonNull, isArray, isBigDecimal, isBigInteger, isBinary, isBoolean, isContainerNode, isDouble, isFloatingPointNumber, isInt, isIntegralNumber, isLong, isMissingNode, isNull, isObject, isPojo, isTextual, iterator, size, textValue, with, withArraypublic NumberNode(JsonNode node)
The argument is a JsonNode because we need our own JsonNodeFactory implementation to generate nodes from numeric Java types
(Byte, Integer and others), and these return instances of
ValueNode instead of NumericNode.
Decimal 0 is special cased: it is unconditionally replaced with BigDecimal.ZERO for hash code consistency (new BigDecimal("0.0")
has hashcode 1 and we want 0 to be consistent with integer value 0 and,
of course, respect the equals/hashCode contract). As a bonus, this allows
to use BigDecimal.equals(Object) instead of BigDecimal.compareTo(BigDecimal) in equals(Object), since only
zero could cause trouble here.
The hashcode is precomputed as being equal to the hash code of the
node's NumericNode.decimalValue(), even if this is an integer
node.
node - the nodeIllegalArgumentException - the node is not a numeric node (JsonNode.isNumber() returns false), or it is a non-integer node
which is not a DecimalNodepublic JsonParser.NumberType numberType()
numberType in interface TreeNodenumberType in class NumericNodepublic void serialize(JsonGenerator jgen, SerializerProvider provider) throws IOException
serialize in interface JsonSerializableserialize in class BaseJsonNodeIOExceptionpublic Number numberValue()
numberValue in class NumericNodepublic int intValue()
intValue in class NumericNodepublic long longValue()
longValue in class NumericNodepublic double doubleValue()
doubleValue in class NumericNodepublic BigDecimal decimalValue()
decimalValue in class NumericNodepublic BigInteger bigIntegerValue()
bigIntegerValue in class NumericNodepublic boolean canConvertToInt()
canConvertToInt in class NumericNodepublic boolean canConvertToLong()
canConvertToLong in class NumericNodepublic String asText()
asText in class NumericNodepublic JsonToken asToken()
Copyright © 2013. All Rights Reserved.