HttpMessageNotReadableException 異常解決

這種異常通常是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;

    ...
    ...
}

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章