Your root node doesn't have a customerSessionId, it has a HotelListResponse. Get that first.
//other methods
public void basicTreeModelRead()
{
JsonNode innerNode = rootNode.get("HotelListResponse"); // Get the only element in the root node
// get an element in that node
JsonNode aField = innerNode.get("customerSessionId");
//the customerSessionId has a String value
String myString = aField.asText();
System.out.println("customerSessionId is:" + myString);
}
This prints
customerSessionId is:0ABAAA7A-90C9-7491-3FF2-7E2C37496CA2
Answer from Sotirios Delimanolis on Stack OverflowMicrosoft Learn
learn.microsoft.com › en-us › dotnet › api › system.text.json.nodes.jsonnode.getvalue
JsonNode.GetValue<T> Method (System.Text.Json.Nodes) | Microsoft Learn
Public Overridable Function GetValue(Of T) () As T · T · The type of the value to obtain from the JsonValue. T · A value converted from the JsonValue instance. FormatException · The current JsonNode cannot be represented as a {TValue}. InvalidOperationException ·
Red Hat
access.redhat.com › webassets › avalon › d › red-hat-jboss-enterprise-application-platform › 7.1.beta › javadocs › com › fasterxml › jackson › databind › JsonNode.html
JsonNode (Red Hat JBoss Enterprise Application Platform 7.1.0.Beta1 public API)
Iterator that can be used to traverse all key/value pairs for object nodes; empty iterator (no contents) for other types · public abstract JsonNode findValue(String fieldName)
Fasterxml
fasterxml.github.io › jackson-databind › javadoc › 2.7 › com › fasterxml › jackson › databind › JsonNode.html
JsonNode (jackson-databind 2.7.0 API)
Iterator that can be used to traverse all key/value pairs for object nodes; empty iterator (no contents) for other types · public abstract JsonNode findValue(String fieldName)
Baeldung
baeldung.com › home › json › jackson › get all the keys in a json string using jsonnode
Get all the Keys in a JSON String Using JsonNode | Baeldung
May 11, 2024 - private void getAllKeysUsingJsonNodeFields(JsonNode jsonNode, List<String> keys) { if (jsonNode.isObject()) { Iterator<Entry<String, JsonNode>> fields = jsonNode.fields(); fields.forEachRemaining(field -> { keys.add(field.getKey()); getAllKeysUsingJsonNodeFieldNames((JsonNode) field.getValue(), keys); }); } else if (jsonNode.isArray()) { ArrayNode arrayField = (ArrayNode) jsonNode; arrayField.forEach(node -> { getAllKeysUsingJsonNodeFieldNames(node, keys); }); } } First, we’ll check whether a JSON value is an object or array.
Top answer 1 of 3
32
Your root node doesn't have a customerSessionId, it has a HotelListResponse. Get that first.
//other methods
public void basicTreeModelRead()
{
JsonNode innerNode = rootNode.get("HotelListResponse"); // Get the only element in the root node
// get an element in that node
JsonNode aField = innerNode.get("customerSessionId");
//the customerSessionId has a String value
String myString = aField.asText();
System.out.println("customerSessionId is:" + myString);
}
This prints
customerSessionId is:0ABAAA7A-90C9-7491-3FF2-7E2C37496CA2
2 of 3
6
Another way to get the inner element, with .at() method:
rootNode.at("/HotelListResponse/customerSessionId")
Makeseleniumeasy
makeseleniumeasy.com › 2020 › 09 › 01 › rest-assured-tutorial-44-fetch-value-from-json-object-using-jsonnode-jackson
REST Assured Tutorial 44 – Fetch Value From JSON Object Using JsonNode – Jackson – get() & path() Methods
We need to use class ObjectMapper provided by Jackson API. ObjectMapper class provides a method “readTree()” which is responsible to deserialize JSON content as tree expressed using a set of JsonNode instances. We can get the value of a node using get() and path() methods of JsonNode class.
Makeseleniumeasy
makeseleniumeasy.com › 2020 › 09 › 16 › rest-assured-tutorial-46-fetch-value-from-json-array-using-jsonnode-jackson-get-path-methods
REST Assured Tutorial 46 – Fetch Value From JSON Array Using JsonNode – Jackson – Get() & Path() Methods
We need to use class ObjectMapper provided by Jackson API. ObjectMapper class provides a method “readTree()” which is responsible to deserialize JSON content as tree expressed using a set of JsonNode instances. We can get the value of a node using get() and path() methods of JsonNode class.
TutorialsPoint
tutorialspoint.com › how-to-access-the-json-fields-arrays-and-nested-objects-of-jsonnode-in-java
How to access the JSON fields, arrays and nested objects of JsonNode in Java?
May 13, 2025 - We can access a field, array or nested object using the get() method of the JsonNode class. We can return a valid string representation using the asText() method and convert the value of the node to a Java int using the asInt() method of JsonNode class.
Baeldung
baeldung.com › home › json › jackson › working with tree model nodes in jackson
Working with Tree Model Nodes in Jackson | Baeldung
January 8, 2024 - This method is well covered in the Jackson – Marshall String to JsonNode article. Please refer to it for more info. A node may be converted from a Java object by calling the valueToTree(Object fromValue) method on the ObjectMapper: ... Let’s see how it works in practice. ... public class NodeBean { private int id; private String name; public NodeBean() { } public NodeBean(int id, String name) { this.id = id; this.name = name; } // standard getters and setters }
Red Hat
access.redhat.com › webassets › avalon › d › jboss_enterprise_application_platform_continuous_delivery › 19 › javadocs › com › fasterxml › jackson › databind › JsonNode.html
JsonNode (Red Hat JBoss Enterprise Application Platform 7.4.0.CD19 public API)
Iterator that can be used to traverse all key/value pairs for object nodes; empty iterator (no contents) for other types · public abstract JsonNode findValue(String fieldName)
Fasterxml
fasterxml.github.io › jackson-core › javadoc › 1.9 › org › codehaus › jackson › JsonNode.html
JsonNode (Jackson JSON Processor)
Null otherwise. public JsonNode get(String fieldName) Method for accessing value of the specified field of an object node. If this node is not an object (or it does not have a value for specified field name), or if there is no field with such name, null is returned.
Fasterxml
fasterxml.github.io › jackson-databind › javadoc › 2.4 › com › fasterxml › jackson › databind › JsonNode.html
JsonNode (jackson-databind 2.4.0 API)
Iterator that can be used to traverse all key/value pairs for object nodes; empty iterator (no contents) for other types · public abstract JsonNode findValue(String fieldName)
Adobe Developer
developer.adobe.com › experience-manager › reference-materials › cloud-service › javadoc › com › fasterxml › jackson › databind › JsonNode.html
JsonNode (The Adobe Experience Manager SDK 2022.11.9850.20221116T162329Z-220900)
Node that represent value of the specified element, if this node is an array and has specified element. Null otherwise. public JsonNode get(java.lang.String fieldName)
Top answer 1 of 2
1
As you said its an Array. Cast the node to an ArrayNode. Select the first element [0] and call the getter. Should be it. Or check out this: https://stackoverflow.com/a/16793133/15565539
2 of 2
0
Instead of 4 lines you can just type
String s = rootnodeResolution.iterator().next().path("id").asText();
Tabnine
tabnine.com › home page › code › java › com.fasterxml.jackson.databind.jsonnode
com.fasterxml.jackson.databind.JsonNode.findValue java code examples | Tabnine
/** * Parses the given JsonNode which is a <code>@context</code> node and find * the value of the <code>@vocab</code> node. * * @param contextJsonNode * @return <code>String</code> the Vocab's value e.g "@vocab": * "http://schema.org" otherwise empty String * @review */ public String getVocabulary(JsonNode contextJsonNode) { JsonNode jsonNode = contextJsonNode.findValue(JSONLDConstants.VOCAB); if (jsonNode == null) { JsonNode missingNode = MissingNode.getInstance(); return missingNode.asText(); } return jsonNode.asText(); }
Sourceforge
weka.sourceforge.io › doc.dev › weka › core › json › JSONNode.html
JSONNode
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait · public JSONNode() Initializes the root container. public JSONNode(java.lang.String name, java.lang.Boolean value) Initializes the primitive container. Parameters: name - the name · value - the primitive value ·
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › system.text.json.nodes.jsonnode.item
JsonNode.Item[] Property (System.Text.Json.Nodes) | Microsoft Learn
public: property System::Text::Json::Nodes::JsonNode ^ default[int] { System::Text::Json::Nodes::JsonNode ^ get(int index); void set(int index, System::Text::Json::Nodes::JsonNode ^ value); }; public System.Text.Json.Nodes.JsonNode? this[int index] { get; set; } member this.Item(int) : System.Text.Json.Nodes.JsonNode with get, set ·