反序列化时为 Jackson 中的 JODA 配置日期时间格式
我正在 Jackson 中使用“完整数据绑定”来反序列化 JSON 字符串中的日期。
这些日期的格式是“EEE MMM dd HH:mm:ss zzz yyyy”。
我正在使用 Jackson 1.8,但我不知道如何配置 ObjectMapper,以便它将这些字符串正确反序列化为 JODA DateTime 对象。
POJO 的片段:
private DateTime deliveryTime;
@JsonProperty("DeliveryTime")
public void setDeliveryTime(DateTime deliveryTime) {
this.deliveryTime = deliveryTime;
}
@JsonProperty("DeliveryTime")
public DateTime getDeliveryTime() {
return deliveryTime;
}
谢谢。
I am using "Full Data Binding" in Jackson to deserialize a date in a JSON string.
The format these dates are coming is "EEE MMM dd HH:mm:ss zzz yyyy".
I'm using Jackson 1.8 and I cannot figure out how to configure the ObjectMapper so it would deserialize these Strings properly into JODA DateTime objects.
Snippet from the POJO:
private DateTime deliveryTime;
@JsonProperty("DeliveryTime")
public void setDeliveryTime(DateTime deliveryTime) {
this.deliveryTime = deliveryTime;
}
@JsonProperty("DeliveryTime")
public DateTime getDeliveryTime() {
return deliveryTime;
}
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
配置 ObjectMapper 使用特定日期/时间格式的最简单方法是调用
ObjectMapper.setDateFormat(...)
方法。创建新的 Joda 数据类型 Jackson 模块有一些初步计划,因为这将使添加强大的新配置变得更加容易;当前的挑战是 Jackson 本身不应该对外部库有硬(静态)依赖(就像我个人喜欢 Joda 一样!),这限制了特定于库的可配置性的工作程度。
The simplest way to configure ObjectMapper to use specific date/time format is to call
ObjectMapper.setDateFormat(...)
method.There are some preliminary plans in creating a new Joda datatype Jackson module, as that would make it much easier to add powerful new configuration; current challenge being that Jackson itself should not have hard (static) dependency to external libraries (as much as I like Joda personally!), which limits degree to which lib-specific configurability can work.