Jackson deserialize date from Twitter to `ZonedDateTime`

前端 未结 2 978
轮回少年
轮回少年 2020-12-10 22:17

I want to deserialize date from Twitter to ZonedDateTime. My program fails on the created_at field deserializing.

My Domain class



        
相关标签:
2条回答
  • 2020-12-10 23:00

    Seems your Locale does not match, try use Locale.ENGLISH:

    SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.ENGLISH);
    

    and

    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss Z yyyy", Locale.ENGLISH);
    
    0 讨论(0)
  • 2020-12-10 23:21

    Try to add this annotation over your property

    @JsonFormat(shape= JsonFormat.Shape.STRING, pattern="EEE MMM dd HH:mm:ss Z yyyy")
    @JsonProperty("created_at") 
    ZonedDateTime created_at;
    
    0 讨论(0)
提交回复
热议问题