Class MarshalledNode
MarshalledMap / MarshalledList and their
JsonMap / JsonList subclasses).
This is a live, mutating view (a façade — not a parallel node hierarchy) wrapping a single backing value which is one of:
- a
Map(an object node), - a
List(an array node), - a scalar value (
String,Number,Boolean, etc.) (a value node), or null (a null node).
It gives Jackson-migrants the ergonomics they expect (node-type introspection, typed value accessors, and fluent
tree building) without replacing the underlying Map/List representation. Because it is a live view,
mutating builders such as put(String,Object) and add(Object) mutate the backing container
in place — callers holding the underlying map/list see the change. Use copy() for an independent
deep-copy snapshot.
Example:
Notes:
- This class is not thread safe.
Beta — API subject to change: This type is part of the next-generation typed tree model layered over the
Marshalled* collections and may change incompatibly in a future release.
-
Method Summary
Modifier and TypeMethodDescriptionAppends a value on an array node, mutating the backingListin place.static MarshalledNodeCreates a new array node backed by a new emptyJsonList.<T> TConverts the raw backing value to the specified type.Returns the backing value converted to aBoolean.asDouble()Returns the backing value converted to aDouble.asInt()Returns the backing value converted to anInteger.asLong()Returns the backing value converted to aLong.asString()Returns the backing value converted to aString.Returns the node addressed by the specified RFC 6901 JSON Pointer relative to this node's backing value.copy()Returns a new node backed by a deep copy of this node's backing value.Optional read variant ofat(String).get(int index) Returns the element node at the specified index on an array node.Returns the child node for the specified key on an object node.booleanisArray()Returnstrue if this node wraps aList(an array node).booleanisNull()Returnstrue if this node wrapsnull .booleanisObject()Returnstrue if this node wraps aMap(an object node).booleanisValue()static MarshalledNodeCreates a new object node backed by a new emptyJsonMap.static MarshalledNodeWraps any value as a node.Adds or replaces an entry on an object node, mutating the backingMapin place.Removes the member or element addressed by the specified RFC 6901 JSON Pointer.Writes the specified value at the location addressed by the specified RFC 6901 JSON Pointer, mutating the backing container in place and auto-vivifying missing intermediate containers.intsize()Returns the number of entries (object) or elements (array) in this node.value()Returns the raw backing value wrapped by this node.
-
Method Details
-
of
Wraps any value as a node.The value is stored as-is (no copy): a
Mapbecomes an object node, aListbecomes an array node, a non-null non-container value becomes a value node, andnull becomes a null node. For navigation and fluent building to work the value should be (or contain) theMarshalledMap/MarshalledListfamily, but anyMap/Listis accepted.- Parameters:
value- The value to wrap. Can benull (creates a null node).- Returns:
- A new node wrapping the value, never
null .
-
objectNode
Creates a new object node backed by a new emptyJsonMap.- Returns:
- A new object node, never
null .
-
arrayNode
Creates a new array node backed by a new emptyJsonList.- Returns:
- A new array node, never
null .
-
isObject
Returnstrue if this node wraps aMap(an object node).- Returns:
true if this is an object node.
-
isArray
Returnstrue if this node wraps aList(an array node).- Returns:
true if this is an array node.
-
isValue
- Returns:
true if this is a value node.
-
isNull
Returnstrue if this node wrapsnull .- Returns:
true if this is a null node.
-
asString
Returns the backing value converted to aString.- Returns:
- The converted value, or
null if this is not a value node or the value cannot be converted.
-
asInt
Returns the backing value converted to anInteger.- Returns:
- The converted value, or
null if this is not a value node or the value cannot be converted.
-
asLong
Returns the backing value converted to aLong.- Returns:
- The converted value, or
null if this is not a value node or the value cannot be converted.
-
asDouble
Returns the backing value converted to aDouble.- Returns:
- The converted value, or
null if this is not a value node or the value cannot be converted.
-
asBoolean
Returns the backing value converted to aBoolean.- Returns:
- The converted value, or
null if this is not a value node or the value cannot be converted.
-
as
Converts the raw backing value to the specified type.Unlike the scalar accessors, this works on object nodes too (e.g. converting a
Mapobject node to a bean). Routes through the same conversion machinery used byMarshalledMap.get(String,Class).- Type Parameters:
T- The type to convert to.- Parameters:
type- The type to convert to.- Returns:
- The converted value, or
null if the backing value isnull or cannot be converted.
-
value
Returns the raw backing value wrapped by this node.- Returns:
- The raw backing value, or
null if this is a null node.
-
get
Returns the child node for the specified key on an object node.- Parameters:
name- The key.- Returns:
- The child node, or
null if this is not an object node or the key is absent.
-
get
Returns the element node at the specified index on an array node.- Parameters:
index- The zero-based index.- Returns:
- The element node, or
null if this is not an array node or the index is out of range.
-
size
Returns the number of entries (object) or elements (array) in this node.- Returns:
- The size, or
0 if this is a value or null node.
-
put
Adds or replaces an entry on an object node, mutating the backingMapin place.- Parameters:
name- The key.value- The value.- Returns:
- This object.
- Throws:
IllegalStateException- If this is not an object node.
-
add
Appends a value on an array node, mutating the backingListin place.- Parameters:
value- The value to append.- Returns:
- This object.
- Throws:
IllegalStateException- If this is not an array node.
-
copy
Returns a new node backed by a deep copy of this node's backing value.Maps are copied into new
JsonMapinstances and lists into newJsonListinstances (recursively); scalars andnull are returned as-is (they are immutable). Mutating the copy does not affect the original and vice versa.- Returns:
- A new independent node, never
null .
-
at
Returns the node addressed by the specified RFC 6901 JSON Pointer relative to this node's backing value.A read-miss (missing key, out-of-range index, or type mismatch) returns
null so callers can null-check. If the addressed value exists and is JSONnull , a null node is returned (useisNull()to test it). The empty pointer addresses this node's whole backing value.- Parameters:
pointer- The RFC 6901 JSON Pointer.- Returns:
- A node wrapping the addressed value, or
null if the addressed value is absent.
-
find
Optional read variant ofat(String).- Parameters:
pointer- The RFC 6901 JSON Pointer.- Returns:
- The addressed node (present, possibly a null node), or an empty
Optionalif the addressed value is absent.
-
set
Writes the specified value at the location addressed by the specified RFC 6901 JSON Pointer, mutating the backing container in place and auto-vivifying missing intermediate containers.Intermediate containers are created based on the next token (a numeric or
- token implies aJsonList, otherwise aJsonMap); the- token on a list appends. Because the backing value isfinal , the empty (root) pointer cannot replace this node's whole document in place and is therefore rejected.- Parameters:
pointer- The RFC 6901 JSON Pointer. Must not be the root pointer.value- The value to set.- Returns:
- This object.
- Throws:
IllegalArgumentException- Ifpointer is the empty/root pointer.
-
remove
Removes the member or element addressed by the specified RFC 6901 JSON Pointer.- Parameters:
pointer- The RFC 6901 JSON Pointer.- Returns:
- The removed value, or
null if the addressed member/element was absent.
-