My JSON structure might be part of the problem but this is what I'm working with:
{
"data":[
{
"id":"1",
"title":"hello"
}
]
}
I want to simply print out the value of id.
Here is my Java main class:
public static void main(String[] args){
ObjectMapper objectMapper = new
ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
List<Data> data = objectMapper.readValue(out, new TypeReference<List<Data>>(){});
System.out.println("data = " + data.get(0).getId());
}
Here is my Data class:
private String id;
private String title;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
It only ever prints null. But it seems like it should work since I have one instance of Data in the List, then I fetch the first (and only) instance and then try to fetch id.