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

查看:36
本文介绍了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 怎么样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.

确实,参考文献中有一个与此相关的问题执行.

Indeed, there is an issue related to this in the reference implementation.

您需要创建并使用 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天全站免登陆