You can use the 'jackson' for deserializing.
Include the dependency using maven
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.0</version>
</dependency>
use ObjectMapper for deserializing your JSON string.
ObjectMapper mapper = new ObjectMapper();
data = mapper.readValue(json, Data[].class);
A complete working example would be as follows
import java.io.IOException;
import com.fasterxml.jackson.databind.ObjectMapper;
public class Test {
static String json = "[\r\n"
+ " {\r\n"
+ " \"id\": \"f9952c24-1b44-4379-9aef-b10075e93562\",\r\n"
+ " \"sections\": [\r\n"
+ " {\r\n"
+ " \"id\": \"7fe9f47e-9cfe-46c7-9c77-
f729b9fb98a4\",\r\n"
+ " \"type\": \"vehicle\",\r\n"
+ " \"summary\": {\r\n"
+ " \"duration\": 23377,\r\n"
+ " \"length\": 480501,\r\n"
+ " \"baseDuration\": 22140\r\n"
+ " }\r\n"
+ " }\r\n"
+ " ]\r\n"
+ " }\r\n"
+ "]";
public static void main(String[] args) {
ObjectMapper mapper = new ObjectMapper();
Test.Data data[] = null;
try {
data = mapper.readValue(json, Data[].class);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(data[0].sections[0].summary.length);
}
private static class Data {
String id;
Sections sections[];
public Data() {
super();
}
public Data(String id, Test.Sections[] sections) {
super();
this.id = id;
this.sections = sections;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Sections[] getSections() {
return sections;
}
public void setSections(Sections[] sections) {
this.sections = sections;
}
}
private static class Sections {
private String id;
private String type;
private Summary summary;
public Sections() {
super();
}
public Sections(String id, String type, Test.Summary summary) {
super();
this.id = id;
this.type = type;
this.summary = summary;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Summary getSummary() {
return summary;
}
public void setSummary(Summary summary) {
this.summary = summary;
}
}
private static class Summary {
private Integer duration;
private Integer length;
private Integer baseDuration;
public Summary() {
super();
}
public Summary(Integer duration, Integer length, Integer baseDuration) {
super();
this.duration = duration;
this.length = length;
this.baseDuration = baseDuration;
}
public Integer getDuration() {
return duration;
}
public void setDuration(Integer duration) {
this.duration = duration;
}
public Integer getLength() {
return length;
}
public void setLength(Integer length) {
this.length = length;
}
public Integer getBaseDuration() {
return baseDuration;
}
public void setBaseDuration(Integer baseDuration) {
this.baseDuration = baseDuration;
}
}
}