JAXB可以处理java.time对象吗? [英] Can JAXB handle java.time objects?

查看:177
本文介绍了JAXB可以处理java.time对象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 JAXB(用于XML绑定的Java架构)可以编组/解组java.util。日期对象,如 Blaise Doughan的回答所示。

I know JAXB (Java Architecture for XML Binding) can marshal/unmarshal java.util.Date objects as seen in this answer by Blaise Doughan.

但是新的 java.time包呢? a> Java 8 中的对象,例如 ZonedDateTime ? JAXB是否已更新以处理这种新的内置数据类型?

But what about the new java.time package objects in Java 8, such as ZonedDateTime? Has JAXB been updated to handle this newly built-in data type?

推荐答案

在Java SE 8中,JAXB尚未更新支持 java.time 类型。

In Java SE 8, JAXB has not been updated yet to support the java.time types.

您需要创建并使用 XmlAdapter 来处理这些类型。使用与 Joda-Time 类似的方法,如本文所述 JAXB和Joda-Time:日期和时间

You need to create and use an XmlAdapter to handle those types. Use an approach similar to that done with Joda-Time as described in this posting, JAXB and Joda-Time: Dates and Times.

您可以使用 java.time 的适配器实现。

You may be able to use this implementation of adapters for java.time.

这篇关于JAXB可以处理java.time对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆