Class NodePointer
- java.lang.Object
-
- software.amazon.smithy.model.node.NodePointer
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description NodeaddValue(Node container, Node value)Adds or replaces avalueincontainerat the JSON pointer location.NodeaddWithIntermediateValues(Node container, Node value)Adds or replaces avalueincontainerat the JSON pointer location.static NodePointerempty()Gets an empty Node pointer.booleanequals(java.lang.Object other)static NodePointerfromNode(Node node)Creates a NodePointer from a Node value.java.util.List<java.lang.String>getParts()Gets the parsed parts of the pointer.NodegetValue(Node container)Gets a value from a container shape at the pointer location.inthashCode()static NodePointerparse(java.lang.String pointer)Parses a JSON pointer.java.lang.StringtoString()static java.lang.Stringunescape(java.lang.String pointerPart)Unescapes special JSON pointer cases.
-
-
-
Method Detail
-
empty
public static NodePointer empty()
Gets an empty Node pointer.- Returns:
- Returns a node pointer with a value of "".
-
fromNode
public static NodePointer fromNode(Node node)
Creates a NodePointer from a Node value.- Parameters:
node- Node value to parse.- Returns:
- Returns the parsed NodePointer.
- Throws:
ExpectationNotMetException- if the pointer cannot be parsed.
-
unescape
public static java.lang.String unescape(java.lang.String pointerPart)
Unescapes special JSON pointer cases.- Parameters:
pointerPart- Pointer to unescape.- Returns:
- Returns the unescaped pointer.
-
parse
public static NodePointer parse(java.lang.String pointer)
Parses a JSON pointer.A JSON pointer that starts with "#/" is treated as "/". JSON pointers must start with "#/" or "/" to be parsed correctly.
- Parameters:
pointer- JSON pointer to parse.- Returns:
- Returns the parsed pointer.
- Throws:
java.lang.IllegalArgumentException- if the pointer does not start with slash (/).
-
getParts
public java.util.List<java.lang.String> getParts()
Gets the parsed parts of the pointer.- Returns:
- Returns the immutable pointer parts.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
getValue
public Node getValue(Node container)
Gets a value from a container shape at the pointer location.When the pointer is "", then provided value is returned. When the pointer is "/", a root object key value of "" is returned. When an invalid property or array index is accessed, a
NullNodeis returned. "-" can be used to access the last element of an array. Any error like accessing an object key from an array or attempting to access an invalid array index will return aNullNode.- Parameters:
container- Node value container to extract a value from.- Returns:
- Returns the extracted value or a
NullNodeif not found.
-
addValue
public Node addValue(Node container, Node value)
Adds or replaces avalueincontainerat the JSON pointer location.When the JSON pointer is "", the entire document is replaced with the given
value. "-" can be used to access the last element of an array or to add an element to the end of an array. Any error like adding an object key to an array or attempting to access an invalid array segment will log a warning and return the given value as-is.- Parameters:
container- Node to update.value- Value to update or replace.- Returns:
- Returns a representation of
containerwith the updated value.
-
addWithIntermediateValues
public Node addWithIntermediateValues(Node container, Node value)
Adds or replaces avalueincontainerat the JSON pointer location.When the JSON pointer is "", the entire document is replaced with the given
value. "-" can be used to access the last element of an array or to add an element to the end of an array. UnlikeaddValue(Node, Node), attempting to add a property to a non-existent object will create a new object and continue adding to the created result.- Parameters:
container- Node to update.value- Value to update or replace.- Returns:
- Returns a representation of
containerwith the updated value.
-
-