Interface JsonNodeReader
-
- All Implemented Interfaces:
@DoNotImplement() public interface JsonNodeReader
Every JsonNodeReader can be thought of as a node in the tree of Json objects being read. Each node in the tree, including the root node represents a value in Json. Every node is referenced in its parent by a field name, except the root node which has no parent. Thus the field name is a property of the parent not the node itself. Writers of deserializers can traverse the tree and extract values of different types in order to construct a class which is represented by Json.
Where the value type of a JsonNodeReader is not a Json object or array, that JsonNodeReader is a leaf in three (no children) from which a single value can be read.
Where the value type of a JsonNodeReader is a Json object it will contain multiple field value pairs, and each of those values is represented by a JsonNodeReader which can be thought of as a child node.
Where the value type of a JsonNodeReader is an array, that array is represented by an iterator of JsonNodeReader objects, which also can be thought of as child nodes.
-
-
Method Summary
Modifier and Type Method Description abstract JsonNodeReaderType
getType()
The type of this node. abstract boolean
isObject()
Returns true if this node represents an object in the Json. abstract Iterator<Map.Entry<String, JsonNodeReader>>
fields()
Get an iterator to map entries which allows iteration over all field names and values in this JsonNodeReader. abstract boolean
hasField(@NotNull() String fieldName)
Determine whether this JsonNodeReader is an object with the specified field. abstract JsonNodeReader
getField(@NotNull() String fieldName)
If this JsonNodeReader represents a Json object, get the value of a field in that object by name. abstract boolean
isArray()
Returns true if this node represents an array in the Json. abstract Iterator<JsonNodeReader>
asArray()
Returns an iterator allowing iteration over a group of JsonNodeReader each of which represents the next value in the array. abstract boolean
isBoolean()
Returns true if this node represents a boolean in the Json. abstract boolean
asBoolean()
This method attempts to convert the underlying Json for this node to a Boolean type. abstract boolean
asBoolean(boolean defaultValue)
This method attempts to convert the underlying Json for this node to a Boolean type. abstract boolean
isNumber()
Returns true if this node represents a number in the Json. abstract Number
numberValue()
If this node represents a number in the underlying Json, this method returns the value as a Number. abstract boolean
isFloatingPointNumber()
Returns true if this node represents a number in the underlying Json and that number has a decimal component. abstract boolean
isDouble()
Returns true if this node represents a double in the Json. abstract double
doubleValue()
If this node represents a number in the underlying Json, this method returns the value as a double
.abstract double
asDouble()
This method attempts to convert the underlying Json for this node to a double type using default Java coercion rules. abstract double
asDouble(double defaultValue)
This method attempts to convert the underlying Json for this node to a Double type using default Java coercion rules. abstract float
floatValue()
If this node represents a Json number type, this method returns the value as a float
.abstract boolean
isInt()
Returns true if this node represents an integer in the Json. abstract boolean
canConvertToInt()
Returns true if this node represents a number in the underlying Json and can be converted to an int
.abstract int
asInt()
This method attempts to convert the underlying Json for this node to an int
type using default Java rules.abstract int
asInt(int defaultValue)
This method attempts to convert the underlying Json for this node to an int
type using default Java rules.abstract boolean
canConvertToLong()
Returns true if this node represents a number in the underlying Json and can be converted to a long
.abstract long
asLong()
This method attempts to convert the underlying Json for this node to a long
type using default Java rules.abstract long
asLong(long defaultValue)
This method attempts to convert the underlying Json for this node to a long
type using default Java rules.abstract short
shortValue()
If this node represents a Json Number type, this method returns the value as a short
.abstract BigInteger
bigIntegerValue()
If this node represents a Json number, this method returns the value as a BigInteger. abstract BigDecimal
bigDecimalValue()
If this node represents a Json number, this method returns the value as a BigDecimal. abstract boolean
isText()
Returns true if this node represents a string in the Json. abstract String
asText()
Returns the value of this node as a String
if the underlying Json value is not an array or object.abstract String
asText(@NotNull() String defaultValue)
Returns the value of this node as a String
if the underlying Json value is not an array or object.abstract Array<byte>
binaryValue()
Returns a byte array if this node represents a string in the Json which contains a base64 encoded byte array. abstract boolean
isNull()
Returns true if this node represents the value of "null" in the underlying Json. abstract <T> T
parse(@NotNull() Class<T> clazz)
Parse this JsonNodeReader to strongly typed objects. -
-
Method Detail
-
getType
@NotNull() abstract JsonNodeReaderType getType()
The type of this node.
-
isObject
abstract boolean isObject()
Returns true if this node represents an object in the Json.
-
fields
@Nullable() abstract Iterator<Map.Entry<String, JsonNodeReader>> fields()
Get an iterator to map entries which allows iteration over all field names and values in this JsonNodeReader. If this node is not representing a Json object, null is returned.
-
hasField
abstract boolean hasField(@NotNull() String fieldName)
Determine whether this JsonNodeReader is an object with the specified field.
- Parameters:
fieldName
- The name of the field.
-
getField
@Nullable() abstract JsonNodeReader getField(@NotNull() String fieldName)
If this JsonNodeReader represents a Json object, get the value of a field in that object by name.
- Parameters:
fieldName
- The name of the field.
-
isArray
abstract boolean isArray()
Returns true if this node represents an array in the Json.
-
asArray
@Nullable() abstract Iterator<JsonNodeReader> asArray()
Returns an iterator allowing iteration over a group of JsonNodeReader each of which represents the next value in the array.
-
isBoolean
abstract boolean isBoolean()
Returns true if this node represents a boolean in the Json.
-
asBoolean
abstract boolean asBoolean()
This method attempts to convert the underlying Json for this node to a Boolean type.
-
asBoolean
abstract boolean asBoolean(boolean defaultValue)
This method attempts to convert the underlying Json for this node to a Boolean type.
- Parameters:
defaultValue
- The value to return if the underlying Json type is not a boolean.
-
isNumber
abstract boolean isNumber()
Returns true if this node represents a number in the Json.
-
numberValue
@Nullable() abstract Number numberValue()
If this node represents a number in the underlying Json, this method returns the value as a Number. Otherwise it returns
null
.
-
isFloatingPointNumber
abstract boolean isFloatingPointNumber()
Returns true if this node represents a number in the underlying Json and that number has a decimal component.
-
isDouble
abstract boolean isDouble()
Returns true if this node represents a double in the Json. This is not the same as asking if the number can be converted to a Double type, which can be the case even if the underlying Json value is not an explicit double. Integers for example are not considered doubles even though they can be easily converted to Double types. See [asDouble] and [doubleValue] for more information.
-
doubleValue
abstract double doubleValue()
If this node represents a number in the underlying Json, this method returns the value as a
double
. Otherwise, it returns 0.0. Note that integers are considered numbers but notdouble
s, thus isDouble will indicate integers are notdouble
s even thoughdoubleValue
will return adouble
quite happily. To convert non-number Json values to Double see asDouble. When the underlying Json represents number which does not fit in adouble
type it is converted using Java coercion rules.
-
asDouble
abstract double asDouble()
This method attempts to convert the underlying Json for this node to a double type using default Java coercion rules. Booleans are converted to 0.0 for false and 1.0 for true. Strings are also parsed and converted as per standard Java rules. Where conversion is not possible 0.0 is returned.
-
asDouble
abstract double asDouble(double defaultValue)
This method attempts to convert the underlying Json for this node to a Double type using default Java coercion rules. Booleans are converted to 0.0 for false and 1.0 for true. Strings are also parsed and converted as per standard Java rules. Where conversion is not possible the supplied default is returned.
- Parameters:
defaultValue
- The value to return if the underlying Json value cannot be converted to a Double.
-
floatValue
abstract float floatValue()
If this node represents a Json number type, this method returns the value as a
float
. Note that there is noasFloat
support, asDouble can be used to convert all Json values to a floating point number. When the underlying Json represents a number which does not fit in afloat
type, it is converted using Java coercion.
-
isInt
abstract boolean isInt()
Returns true if this node represents an integer in the Json. This is not the same as asking if the number can be converted to an Int, see asInt for more information.
-
canConvertToInt
abstract boolean canConvertToInt()
Returns true if this node represents a number in the underlying Json and can be converted to an
int
. It includes floating point numbers which have an integral part which does not overflow anint
. See also isFloatingPointNumber.
-
asInt
abstract int asInt()
This method attempts to convert the underlying Json for this node to an
int
type using default Java rules. Booleans are converted to 0 for false and 1 for true. Strings are also parsed and converted as per standard Java rules. Where conversion is not possible 0 is returned.
-
asInt
abstract int asInt(int defaultValue)
This method attempts to convert the underlying Json for this node to an
int
type using default Java rules. Booleans are converted to 0 for false and 1 for true.String
s are also parsed and converted as per standard coercion Java rules. Where conversion is not possible the supplied default is returned.- Parameters:
defaultValue
- The value to return if the underlying Json cannot be converted to anint
.
-
canConvertToLong
abstract boolean canConvertToLong()
Returns true if this node represents a number in the underlying Json and can be converted to a
long
. It includes floating point numbers which have an integral part which does not overflow along
. See also isFloatingPointNumber.
-
asLong
abstract long asLong()
This method attempts to convert the underlying Json for this node to a
long
type using default Java rules. Booleans are converted to 0L for false and 1L for true. Strings are also parsed and converted as per Java coercion rules. Where conversion is not possible 0L is returned.
-
asLong
abstract long asLong(long defaultValue)
This method attempts to convert the underlying Json for this node to a
long
type using default Java rules. Booleans are converted to 0L for false and 1L for true. Strings are also parsed and converted as per standard Java rules. Where conversion is not possible the supplied default is returned.- Parameters:
defaultValue
- The value to return if the underlying Json cannot be converted to along
.
-
shortValue
abstract short shortValue()
If this node represents a Json Number type, this method returns the value as a
short
. Note that there is noasShort
support, asInt can be used to attempt to convert all Json values to an integer. When the underlying Json represents a number which does not fit in aShort
type, it is converted using Java coercion.
-
bigIntegerValue
@NotNull() abstract BigInteger bigIntegerValue()
If this node represents a Json number, this method returns the value as a BigInteger.
-
bigDecimalValue
@NotNull() abstract BigDecimal bigDecimalValue()
If this node represents a Json number, this method returns the value as a BigDecimal.
-
isText
abstract boolean isText()
Returns true if this node represents a string in the Json.
-
asText
@NotNull() abstract String asText()
Returns the value of this node as a
String
if the underlying Json value is not an array or object. If it is an array or object an emptyString
is returned. If the Json value is null, the string "null" is returned.
-
asText
@NotNull() abstract String asText(@NotNull() String defaultValue)
Returns the value of this node as a
String
if the underlying Json value is not an array or object. If it is an array or object a defaultString
is returned. If the Json value is null, the string "null" is returned.- Parameters:
defaultValue
- The default value to return if this node is an array or object type.
-
binaryValue
@Nullable() abstract Array<byte> binaryValue()
Returns a byte array if this node represents a string in the Json which contains a base64 encoded byte array.
-
isNull
abstract boolean isNull()
Returns true if this node represents the value of "null" in the underlying Json.
-
parse
@Nullable() abstract <T> T parse(@NotNull() Class<T> clazz)
Parse this JsonNodeReader to strongly typed objects. Will deserialize using default deserializers or any custom Json deserializers registered. This method can be used if during custom deserialization of one class type, the deserializer expects a field's value to contain a Json object which can be deserialized to another class type which is already known to either be default deserializable, or for which other custom deserializers are registered. It is the equivalent of calling the JsonMarshallingService parse method on a Json string representation of this node.
- Parameters:
clazz
- The type to try and parse this node into.
-
-
-
-