restTemplate.getForObject 没有读取 json 数组信息

restTemplate.getForObject doesn't read json array information

我很难读取一个 json 数据,其中对象和数组混合在他的体内。

我可以读取和转换所有对象类型,但 预测节点是一个数组,我总是收到 null 作为响应

查看下面的更多详细信息:

我的网站API给我json回复:

{
  "location": {
    "name": "Brasilia"

  },
  "current": {
    "last_updated": "2019-01-11 19:00",
    "condition": {
        "text": "Patchy rain possible"
    }
  },
  "forecast": {
    "forecastday": [
      {
        "date": "2019-01-11",
        "day": {
          "avgtemp_c": 21.4
        }
      },
      {
        "date": "2019-01-12",
        "day": {
          "avgtemp_c": 22.0
         }
      }
    ]
  }
}

我正在使用 restTemplate 获取数据:

ApiResponse apiResponse = restTemplate.getForObject(uri, ApiResponse.class);

这是我的 ApiResponse 响应结构:

@JsonIgnoreProperties(ignoreUnknown = true)
public class ApiResponse {

    private Location location;
    private Current current; 
    private Forecast forecast;

    /*constructors, getters and setters mmited */
}   

@JsonIgnoreProperties(ignoreUnknown = true)
public class Location {

    private String name;    
    private String region;
    private String country;
    private Float lat;
    private Float lon;
    private String localtime;

    /*constructors, getters and setters mmited */
}

@JsonIgnoreProperties(ignoreUnknown = true)
public class Current {

    private String  last_updated;  
    private Float   temp_c;
    private Float   precip_mm;
    private Condition condition;

    /*constructors, getters and setters mmited */
}

@JsonIgnoreProperties(ignoreUnknown = true)
public class Forecast  {

    public List<Forecastday> forecastday;

    /*constructors, getters and setters mmited */
}

@JsonIgnoreProperties(ignoreUnknown = true)
public class Forecastday  {

    private String date; 
    private Day day;

    /*constructors, getters and setters mmited */
}

@JsonIgnoreProperties(ignoreUnknown = true)
public class Day {

    private Float  avgtemp_c;
    private Float totalprecip_mm;
    private List<Condition> condition;

    /*constructors, getters and setters mmited */
}

我想我做 class 映射的方式不对,但我看不出问题出在哪里。

谁能帮帮我?

大家好,我发现了错误。

我的映射真的错了!

在我的最后一个 class 中:private List<Condition> condition; 不是一个列表而是一个简单的对象:private Condition condition; 因为这个我收到了一个 Cannot deserialize instance ofjava.util.ArrayListout of START_OBJECT token

This another thread help me to see where i did wrong.