以下のJSONを受け取ったとします。
{"item":{"title":"my title","expires":"2017-01-07T18:46:19Z"}}
Item.java:
@JsonRootName("item")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Item {
public String title;
public Date expires;
@Override
public String toString() {
return "Item{" +
"title='" + title + '\'' +
", expires=" + expires +
'}';
}
}
使いたいDateFormat
とObjectMapper
を設定します。
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"));
Item t1 = mapper.readValue(jsonString, Item.class);
このリンクはあなたを助けることができる - のhttp://wiki.fasterxmlを。 com/JacksonFAQDateHandling – Arpit