如何使用 Spring RestTemplate 从数组中的其他对象中获取 JSON 对象的列表?
How do I get a list of JSON objects out of an array among other objects using Spring RestTemplate?
我正在尝试使用此数据
https://api.nasa.gov/neo/rest/v1/neo/browse?api_key=DEMO_KEY
遵循
中的教程
我成功检索了数据的 "links" 和 "page" 部分,但是 near_earth_objects 的数组为空。
我尝试了 post 中的建议:
Get list of JSON objects with Spring RestTemplate
但我的情况有点复杂,因为它不仅仅是
中看到的一个充满对象的数组
顶部答案给出错误:
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not
deserialize instance of java.lang.Object[] out of START_OBJECT token
这是我的 POJO 的样子:
@JsonIgnoreProperties(ignoreUnknown = true)
public class NearEarthObjectBrowse {
@Id
private Links links;
private Page page;
private NearEarthObject[] near_earth_objects;
我也尝试对 NearEarthObject
数组使用包装器 class,但仍然无法成功编组。
一般来说,有没有更好的方法来做到这一点?
编辑:我相信 NearEarthObject 的结构与数据相匹配。这是我的 github
尝试使用列表而不是数组 near_earth_objects
@JsonProperty("near_earth_objects")
private List<NearEarthObject> near_earth_objects;
我正在尝试使用此数据
https://api.nasa.gov/neo/rest/v1/neo/browse?api_key=DEMO_KEY
遵循
中的教程我成功检索了数据的 "links" 和 "page" 部分,但是 near_earth_objects 的数组为空。
我尝试了 post 中的建议:
Get list of JSON objects with Spring RestTemplate
但我的情况有点复杂,因为它不仅仅是
中看到的一个充满对象的数组顶部答案给出错误:
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not
deserialize instance of java.lang.Object[] out of START_OBJECT token
这是我的 POJO 的样子:
@JsonIgnoreProperties(ignoreUnknown = true)
public class NearEarthObjectBrowse {
@Id
private Links links;
private Page page;
private NearEarthObject[] near_earth_objects;
我也尝试对 NearEarthObject
数组使用包装器 class,但仍然无法成功编组。
一般来说,有没有更好的方法来做到这一点?
编辑:我相信 NearEarthObject 的结构与数据相匹配。这是我的 github
尝试使用列表而不是数组 near_earth_objects
@JsonProperty("near_earth_objects")
private List<NearEarthObject> near_earth_objects;