Hire QA – Specialized in QA Recruitment, Technical Interviews and Testing Solutions

Retrieve All Field Values From From JSON Object Or ObjectNode

Category: Rest Assured

To retrieve all field values from an ObjectNode, use elements() method which returns an Iterator of JsonNode.

Example Code for Json Object:

{
       "firstname" : "Phani",
       "lastname" : "Nagula"
}
// Create an object to ObjectMapper
ObjectMapper objectMapper = new ObjectMapper();
		
// Creating Node that maps to JSON Object structures in JSON content
ObjectNode employeeInfo = objectMapper.createObjectNode();

employeeInfo.put("firstname", "Phani");
employeeInfo.put("lastname", "Nagula");


// To get all field values
Iterator allFieldValues = employeeInfo.elements();
System.out.println("Fields values are : ");
while(allFieldValues.hasNext())
{
    System.out.println(allFieldValues.next());
}

Leave a Reply

Your email address will not be published. Required fields are marked *