Jackson: How to parse named root Array?

Viewed 26

probably the question has been asked many times and I'm just using the wrong term to find the answers.

I want to parse the following JSON as an array:

{
   "entries":[
      {
         "id":"1",
         "name":"Test 1"
      },
      {
         "id":"2",
         "name":"Test 2"
      }
    ]
}

My class looks like:

@JsonRootName(value = "entries")
public class Entries {

    private String id;

    private String name;

    // Getter + Setter
}

The code to read this JSON with Jackson looks like:

objectMapper.readValue(givenJsonString, Entries[].class);

Or is a second wrapper class unavoidable? Does anyone have any helpful tips?

Thanks!

0 Answers
Related