Search code examples
javarestrest-assuredrest-assured-jsonpath

How to retrieve jsonObjects from a arraylist api response in Java


How to get jsonObjects from this below rest api response, using restAassured and java.

My rest api is returning response as below.

[
    {
        "id": {
            "value": "1"
        },
        "fieldName": "input",
        "jobId": "234"
    },
    {
        "id": {
            "value": "2"
        },
        "fieldName": "output",
        "jobId": "223"
    }
]

I have tried using rest assured response parsing methods like jsonPath(), getJsonObject() etc., nothing works. Can you please help.


Solution

  • ObjectMapper objectMapper = new ObjectMapper();
    ArrayNode arrayNode = objectMapper.readValue(<OUTPUT_STRING>,ArrayNode.class)