這種異常通常是jackson反序列化失敗引起,例如
InvalidFormatException: Can not deserialize value of type java.util.Date
獲取天氣信息
RestTemplate template = new RestTemplate();
Weather weather = template.getForObject("https://www.tianqiapi.com/api?version=v1&ip={ip}", Weather.class, IPUtil.getIpAddr(request));
需要在Weather的屬性update_time加入json解析註解
public class Weather {
private String cityid;
@com.fasterxml.jackson.annotation.JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date update_time;
...
...
}