jazzertron jazzertron - 9 months ago 61
JSON Question

How do I get a list of JSON objects out of an array among other objects using Spring RestTemplate?

I'm trying to consume this data


following the tutorial from


I successfully retrieve the "links" and "page" portions of the data, but the array of near_earth_objects is null.

I tried what was suggested in this post:

Get list of JSON objects with Spring RestTemplate

But my situation is a little more complicated because it's more than just one array filled with objects as seen in


Top answer gives error:

Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not
deserialize instance of java.lang.Object[] out of START_OBJECT token

Here is what my POJO looks like:

@JsonIgnoreProperties(ignoreUnknown = true)
public class NearEarthObjectBrowse {
private Links links;
private Page page;
private NearEarthObject[] near_earth_objects;

I also tried using a wrapper class for the
array and still was unable to marshal successfully.

Is there a better way to go about doing this in general?

Edit: I believe the structure of NearEarthObject matches the data. Here is my github

Answer Source

Try to use A list instead of an array for near_earth_objects

private List<NearEarthObject> near_earth_objects;