2

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.

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'.]

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

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:

  • 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

Any suggestions?

Jim Tough
  • 14,843
  • 23
  • 75
  • 96

1 Answers1

3

Issue #1

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

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.

Issue #2

The attribute required is undefined for the annotation type XmlElementRef

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.

bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • 1
    Thanks very much for taking the time to help me Blaise. I'll check these out at the office tomorrow. – Jim Tough Jan 09 '13 at 00:04
  • Correct in both cases. I'm not sure why the older version of JAXB allowed those timestamps to be unmarshalled as xs:date, but it did. I fixed my unit test data to remove the time component and all is good. I downloaded the current JAXB release (version 2.2.6) and it all seems to work fine. Thanks again! – Jim Tough Jan 09 '13 at 12:32
  • I believe you have binding file which created an adapter on datetime XML data type, I just removed it, and generated the JAXB classes again, the java data type is converted from Date to XMLGregorianType. – Bassel Kh Jan 26 '16 at 08:23