反序列化时为 Jackson 中的 JODA 配置日期时间格式

发布于 2024-12-06 01:50:18 字数 487 浏览 4 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱&纷飞 2024-12-13 01:50:18

配置 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文