Package io.micronaut.json.tree
Class JsonNode
java.lang.Object
io.micronaut.json.tree.JsonNode
- Direct Known Subclasses:
JsonArray
,JsonObject
Immutable class representing a json node. Json nodes can be either scalar (string, number, boolean, null) or
containers (object, array).
- Since:
- 3.1
- Author:
- Jonas Konrad
-
Method Summary
Modifier and TypeMethodDescriptionAttempt to coerce this node to a string.createArrayNode
(@NonNull List<JsonNode> nodes) createBooleanNode
(boolean value) createNumberNode
(double value) createNumberNode
(float value) createNumberNode
(int value) createNumberNode
(long value) createNumberNode
(@NonNull BigDecimal value) createNumberNode
(@NonNull BigInteger value) static JsonNode
createNumberNodeImpl
(Number value) Hidden, so that we don't have to check that the number type is supported.createObjectNode
(Map<String, JsonNode> nodes) createStringNode
(@NonNull String value) entries()
Create a newJsonNode
representing this value.get
(int index) final @NonNull BigDecimal
final @NonNull BigInteger
boolean
final double
final float
final int
final long
getValue()
Get the value reprinting this node.boolean
isArray()
boolean
boolean
boolean
isNull()
boolean
isNumber()
boolean
isObject()
boolean
isString()
boolean
nullNode()
abstract int
size()
values()
-
Method Details
-
from
Create a newJsonNode
representing this value. -
nullNode
- Returns:
- The singleton node representing
null
.
-
createArrayNode
- Parameters:
nodes
- The nodes in this array. Must not be modified after this method is called.- Returns:
- The immutable array node.
-
createObjectNode
- Parameters:
nodes
- The nodes in this object. Must not be modified after this method is called.- Returns:
- The immutable array node.
-
createBooleanNode
- Parameters:
value
- The value of the node.- Returns:
- A json node representing the given boolean value.
-
createStringNode
- Parameters:
value
- The value of the node.- Returns:
- A json node representing the given string value.
-
createNumberNodeImpl
Hidden, so that we don't have to check that the number type is supported.- Parameters:
value
- The raw numeric value.- Returns:
- The number node.
-
createNumberNode
- Parameters:
value
- The value of the node.- Returns:
- A json node representing the given numeric value.
-
createNumberNode
- Parameters:
value
- The value of the node.- Returns:
- A json node representing the given numeric value.
-
createNumberNode
- Parameters:
value
- The value of the node.- Returns:
- A json node representing the given numeric value.
-
createNumberNode
- Parameters:
value
- The value of the node.- Returns:
- A json node representing the given numeric value.
-
createNumberNode
- Parameters:
value
- The value of the node.- Returns:
- A json node representing the given numeric value.
-
createNumberNode
- Parameters:
value
- The value of the node.- Returns:
- A json node representing the given numeric value.
-
getValue
Get the value reprinting this node.- Returns:
- The value of the node
- Since:
- 4.0.0
-
isNumber
public boolean isNumber()- Returns:
true
iff this is a number node.
-
getNumberValue
- Returns:
- The raw numeric value of this node. Always full precision.
- Throws:
IllegalStateException
- if this is not a number node.
-
getIntValue
public final int getIntValue()- Returns:
- The value of this number node, converted to
int
. May lose precision. - Throws:
IllegalStateException
- if this is not a number node.
-
getLongValue
public final long getLongValue()- Returns:
- The value of this number node, converted to
long
. May lose precision. - Throws:
IllegalStateException
- if this is not a number node.
-
getFloatValue
public final float getFloatValue()- Returns:
- The value of this number node, converted to
float
. May lose precision. - Throws:
IllegalStateException
- if this is not a number node.
-
getDoubleValue
public final double getDoubleValue()- Returns:
- The value of this number node, converted to
double
. May lose precision. - Throws:
IllegalStateException
- if this is not a number node.
-
getBigIntegerValue
- Returns:
- The value of this number node, converted to
BigInteger
. May lose the decimal part. - Throws:
IllegalStateException
- if this is not a number node.
-
getBigDecimalValue
- Returns:
- The value of this number node, converted to
BigDecimal
. - Throws:
IllegalStateException
- if this is not a number node.
-
isString
public boolean isString()- Returns:
true
iff this is a string node.
-
getStringValue
- Returns:
- The value of this string node.
- Throws:
IllegalStateException
- if this is not a string node.
-
coerceStringValue
Attempt to coerce this node to a string.- Returns:
- The coerced string value.
- Throws:
IllegalStateException
- if this node is not a scalar value
-
isBoolean
public boolean isBoolean()- Returns:
true
iff this is a boolean node.
-
getBooleanValue
public boolean getBooleanValue()- Returns:
- The value of this boolean node.
- Throws:
IllegalStateException
- if this is not a boolean node.
-
isNull
public boolean isNull()- Returns:
true
iff this is the null node.
-
size
public abstract int size()- Returns:
- The number of immediate children of this node, or
0
if this is not a container node.
-
values
- Returns:
- An
Iterable
of all values of this array or object node. - Throws:
IllegalStateException
- if this is not a container node.
-
entries
- Returns:
- An
Iterable
of all entries of this object node. - Throws:
IllegalStateException
- if this is not an object node.
-
isValueNode
public boolean isValueNode()- Returns:
true
iff this node is a value node (string, number, boolean, null).
-
isContainerNode
public boolean isContainerNode()- Returns:
true
iff this node is a container node (array or object).
-
isArray
public boolean isArray()- Returns:
true
iff this node is an array node.
-
isObject
public boolean isObject()- Returns:
true
iff this node is an object node.
-
get
- Parameters:
fieldName
- The field name.- Returns:
- The field with the given name, or
null
if there is no such field or this is not an object.
-
get
- Parameters:
index
- The index into this array.- Returns:
- The field at the given index, or
null
if there is no such field or this is not an array.
-