public interface Node
This interface provide convenience methods to convert the node
that it represents into more specific types, such as
primitive types (boolean, string, int, long, double);
it also contains two generic
methods: as(Class)
and as(TypeToken)
that
can convert this node into any arbitrary Java type, provided
that the underlying serialization runtime has been correctly configured
to support the requested conversion.
Modifier and Type | Method and Description |
---|---|
<T> T |
as(Class<T> clazz)
Deserializes and returns this node as an instance of
clazz . |
<T> T |
as(com.google.common.reflect.TypeToken<T> type)
Deserializes and returns this node as an instance of the given
type . |
boolean |
asBoolean()
Returns this node as a boolean.
|
double |
asDouble()
Returns this node as a double.
|
int |
asInt()
Returns this node as an integer.
|
long |
asLong()
Returns this node as a long integer.
|
Map<String,Object> |
asMap()
Deserializes and returns this node as an instance of
Map<String, Object> . |
String |
asString()
Returns a valid String representation of this node,
if the node is a simple node (i.e.
|
Iterator<String> |
fieldNames()
Returns all the field names of the current node, if it is an object,
or an empty iterator otherwise.
|
Node |
get(int index)
Returns the element node at the specified
index of an array node. |
Node |
get(String fieldName)
Returns the value of the specified field of an object node.
|
boolean |
isArray()
Returns whether this node is an array.
|
boolean |
isNull()
Returns whether this node is
null . |
boolean |
isObject()
Returns whether this node is an object.
|
boolean |
isValue()
Returns whether this node is a simple value,
i.e.
|
int |
size()
Returns the size of the current node,
if it is an array, or
0 otherwise. |
boolean isNull()
null
.true
if this node is null
, false
otherwise.boolean isObject()
Only one method out of isObject()
, isArray()
and
isValue()
should ever return true
for one given node.
true
if this node is an object, false
otherwise.boolean isArray()
Only one method out of isObject()
, isArray()
and
isValue()
should ever return true
for one given node.
true
if this node is an array, false
otherwise.boolean isValue()
null
.
Only one method out of isObject()
, isArray()
and
isValue()
should ever return true
for one given node.
false
otherwise.Iterator<String> fieldNames()
Iterator
of all the field names of the current node.int size()
0
otherwise.0
otherwise.int asInt()
If this node can not be converted to an int
(including structured types like Objects and Arrays),
0
will be returned; no exceptions will be thrown.
0
if this node can not be converted to an int.boolean asBoolean()
If this node can not be converted to a boolean
(including structured types like Objects and Arrays),
false
will be returned; no exceptions will be thrown.
false
if this node can not be converted to a boolean.long asLong()
0L
if this node is null
.double asDouble()
0.0D
if this node is null
.String asString()
Map<String,Object> asMap()
Map<String, Object>
.Map<String, Object>
.DriverException
- if this node cannot be converted to a map.<T> T as(Class<T> clazz)
clazz
.
Before attempting such a conversion, there must be an appropriate converter configured on the underlying serialization runtime.
clazz
- the class to convert this node into.clazz
.DriverException
- if this node cannot be converted to the given class.<T> T as(com.google.common.reflect.TypeToken<T> type)
type
.
Before attempting such a conversion, there must be an appropriate converter configured on the underlying serialization runtime.
type
- the type to convert this node into.type
.DriverException
- if this node cannot be converted to the given type.Node get(String fieldName)
If this node is not an object (or it does not have a value
for the specified field name), or if there is no field with
such name, null
is returned.
If the property value has been explicitly set to null
,
implementors may return a special "null node" instead of null
.
fieldName
- the field name to fetch.null
if it does not exist.Node get(int index)
index
of an array node.
For all other node types, null
is returned.
If index
is out of bounds, (i.e. less than zero or >= size()
,
null
is returned; no exception will be thrown.
If the requested element has been explicitly set to null
,
implementors may return a special "null node" instead of null
.
index
- the element index to fetch.null
if it does not exist.