Include Jackson dependency so you're able to deserialize the JSON without parsing it manually
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.4</version>
</dependency>
Create a POJO representation of your object. To have predicted_route
mapped to the correct field you can annotate it with @JsonProperty
.
class Route {
@JsonProperty("predicted_route")
private List<Integer> predictedRoute;
public List<Integer> getPredictedRoute(){
return predictedRoute;
}
public void setPlannedRoute(List<Integer> route){
this.plannedRoute = route;
}
}
Map the JSON string to your object
String yourJson = "{\\"predicted_route\\": [1, 351, 371, 372, 373, 0]}";
Route myRoute = new ObjectMapper().readValue(yourJson, Route.class);
System.out.println(myRoute.getPredictedRoute());