从Java 5 SE迁移到Java 6 SE后,JAXB的“日期”转换失败 [英] JAXB 'date' conversions fail after moving from Java 5 SE to Java 6 SE

查看:61
本文介绍了从Java 5 SE迁移到Java 6 SE后,JAXB的“日期”转换失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将现有应用程序的Java JDK版本从Java 5更改为Java 6(更新38)。该应用程序使用一些JAXB生成的类来编组/解组我们从远程服务器发送/接收的XML。 XML符合模式(.xsd)文件。

I'm trying to change the Java JDK version for an existing application from Java 5 to Java 6 (update 38). The application uses some JAXB generated classes to marshal/unmarshal XML that we send/receive from a remote server. The XML conforms to a schema (.xsd) file.

这一切都在Java 5下运行正常,并在类路径中下载了一堆JAXB二进制文件。我不确定下载的JAXB二进制文件的版本是什么(这个项目已经在我面前了)。如果我只是将JDK版本从Java 5更改为Java 6(更新38),那么我会得到一些以前从未发生过的单元测试失败,例如:

This all used to work fine under Java 5 with a downloaded bundle of JAXB binaries in the classpath. I'm not sure what the version of the downloaded JAXB binaries was (this project was already here before me). If I just change the JDK version from Java 5 to Java 6 (update 38), then I get a few unit test failures that never happened before, such as:

[org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.1: '2012-08-22T00:00:00-04:00' is not a valid value for 'date'.]

我想我可以通过将Java 6 JDK移到头来解决这个问题类路径,所以它在外部JAXB二进制文件之前找到。这产生了编译时错误,例如:

I thought I might be able to solve this by moving the Java 6 JDK to the head of the classpath, so it is found before the external JAXB binaries. That yielded compile-time errors, such as:

The attribute required is undefined for the annotation type XmlElementRef

我的一个JAXB生成的类(基于.xsd文件)报告了此错误。错误是由此注释行引起的:

This error was reported on one of my JAXB-generated classes (based on the .xsd file). The error was caused by this annotation line:

@XmlElementRef(name = "DealCalendarId", type = JAXBElement.class, required = false)

所以,我不确定接下来我需要做什么。我有一些想法:

So, I'm not sure what I need to do next. I have a few ideas:


  • 删除下载的JAXB二进制文件,并仅依赖于Java 6 SE中的内置JAXB支持(但我似乎记得前一段时间没有在项目上工作......)

  • 用新版本替换下载的JAXB二进制文件

  • 替换下载的具有较新版本的JAXB二进制文件并将Java 6 JDK放在类路径中

  • 执行上述操作之一并重新生成基于.xsd的所有JAXB类

  • Remove the downloaded JAXB binaries and rely only on the built-in JAXB support in Java 6 SE (but I seem to remember this not working on a project some time ago...)
  • Replace the downloaded JAXB binaries with a newer version
  • Replace the downloaded JAXB binaries with a newer version AND put the Java 6 JDK after them in the classpath
  • Do one of the above and also regenerate all my JAXB classes that are based on the .xsd

有什么建议吗?

推荐答案

问题#1


[org.xml.sax.SAXParseException:cvc-datatype-valid.1.2.1:
'2012-08-22T00:00:00-04:00'不是'date'的有效值。]

[org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.1: '2012-08-22T00:00:00-04:00' is not a valid value for 'date'.]

仅通过此消息 2012-08-22T00:00:00-04:00 不是XML架构的有效值 date type,有效值为 2012-08-22 没有时间信息。您提供的值将对应于 dateTime 类型。您使用的其他版本可能无法执行此验证。

Only going by this message 2012-08-22T00:00:00-04:00 is not a valid value for the XML Schema date type, a valid value would be 2012-08-22 without the time information. The value you presented would correspond to the dateTime type. It is possible that the other version you were using just wan't performing this validation.

问题#2


注释类型未定义所需的属性
XmlElementRef

The attribute required is undefined for the annotation type XmlElementRef

Java SE 6包含JAXB 2.1,您必须在Java SE 5中使用JAXB 2.2,其中 @XmlElementRef 注释包含 required property。

Java SE 6 contains JAXB 2.1, you must have been using JAXB 2.2 with Java SE 5 where the @XmlElementRef annotation contains the required property.

这篇关于从Java 5 SE迁移到Java 6 SE后,JAXB的“日期”转换失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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