jaxp
  1. jaxp
  2. JAXP-73

Problem unmarshalling duration-type fields containing whitespace

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: current
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: Windows XP
      Platform: All

    • Issuezilla Id:
      590

      Description

      The following problem could be observed in Jaxb 2.1:

      Having an XML schema that defines the following type:
      <element name="PublishedStartTime" type="dateTime" minOccurs="0"/>

      and an having an XML instance document with the following entry:
      <tva:PublishedStartTime>
      2008-11-01T00:00:00Z
      </tva:PublishedStartTime>

      ... i.e. with trailing and leading whitespaces, will result in an an
      unmarshalled PublishedStartTime of null instead of the expected date and time.

      The problem does not occur, if the entry in the XML instance document looks as
      follows:

      <tva:PublishedStartTime>2008-11-01T00:00:00Z</tva:PublishedStartTime>

      ... i.e. there are no leading and trailing whitespaces.
      The Jaxb-classes generated with XJC use XMLGregorianCalendar as the data type
      holding dateTime types.

      The problem seems to be that the XMLGregorianCalendar / DatatypeFactory does not
      support input strings with leading and trailing whitespaces as documented in
      http://java.sun.com/javase/6/docs/api/javax/xml/datatype/DatatypeFactory.html#newXMLGregorianCalendar(java.lang.String).
      Additionally it seems that the Jaxb2.1 runtime does not remove leading and
      trailing whitespaces from dateTime entries.

      We believe this is a bug, since either XMLGregorianCalendar should support
      leading and trailing whitespaces, or Jaxb2.1 RI should remove leading and
      trailing whitepsaces for dateTime entries. Otherwise, another JavaType than
      XMLGregorianCalendar should be used as default type for xsd:dateTime types.

      Best regards,

      Hao and Florian

        Activity

        Hide
        gturner added a comment -

        Ooops!

        Sorry I used the JIRA "Clone" link from bug 590. I didn't realize it would copy the initial comment. Version number, environment, etc. are wrong too.

        I am using 2.1.13 and am experiencing the same effect on duration types.

        e.g.

        <StartTime>
        2006-12-05T09:36:48.596-08:00
        </StartTime>
        <ExpireTime>
        PT1H
        </ExpireTime>

        System.out.println(object.getStartTime()); // => 2006-12-05T09:36:48.596-08:00; Good! Bug 590 fixed.
        System.out.println(object.getExpireTime()); // => null; Bad! Similar to bug 590.

        Show
        gturner added a comment - Ooops! Sorry I used the JIRA "Clone" link from bug 590. I didn't realize it would copy the initial comment. Version number, environment, etc. are wrong too. I am using 2.1.13 and am experiencing the same effect on duration types. e.g. <StartTime> 2006-12-05T09:36:48.596-08:00 </StartTime> <ExpireTime> PT1H </ExpireTime> System.out.println(object.getStartTime()); // => 2006-12-05T09:36:48.596-08:00; Good! Bug 590 fixed. System.out.println(object.getExpireTime()); // => null; Bad! Similar to bug 590.
        Hide
        Martin Grebac added a comment -

        Thanks for filing this - would you please also attach a simple testcase?

        Show
        Martin Grebac added a comment - Thanks for filing this - would you please also attach a simple testcase?
        Hide
        gturner added a comment -

        Hi Martin, I was going to write a testcase with the jaxb source, but it appears that jaxb-unit is not open source - http://www.java.net/node/693249 - is this still true?

        Show
        gturner added a comment - Hi Martin, I was going to write a testcase with the jaxb source, but it appears that jaxb-unit is not open source - http://www.java.net/node/693249 - is this still true?
        Hide
        Martin Grebac added a comment -

        Yes, still true. You don't need to follow any guidelines/layout/whatever - anything I can execute is fine - just so that it contains the xsd/xml and the code you use.

        Show
        Martin Grebac added a comment - Yes, still true. You don't need to follow any guidelines/layout/whatever - anything I can execute is fine - just so that it contains the xsd/xml and the code you use.
        Hide
        gturner added a comment -

        Attached is a testcase, a self-contained project using Ant, not JUnit or anything, may have lots of trouble running with dll-hell that is Xerces and JAXB inclusion in JRE. Here are the relevant bits:

        test.xsd:

        <xs:element name="document">
        <xs:complexType>
        <xs:sequence>
        <xs:element name="duration" type="xs:duration" maxOccurs="unbounded"/>
        </xs:sequence>
        </xs:complexType>
        </xs:element>

        test.xml:

        <document xmlns="urn:test">
        <duration>PT1H</duration>
        <duration> PT1H</duration>
        <duration>PT1H </duration>
        <duration> PT1H </duration>
        <duration>
        PT1H
        </duration>
        </document>

        Test.java:

        for (Duration duration : doc.getDuration())
        if (duration != null)
        System.out.println("Got duration " + duration);
        else
        System.err.println("Got NULL duration!");

        Ant output:

        [java] Got duration PT1H
        [java] Got NULL duration!
        [java] Got NULL duration!
        [java] Got NULL duration!
        [java] Got NULL duration!

        Show
        gturner added a comment - Attached is a testcase, a self-contained project using Ant, not JUnit or anything, may have lots of trouble running with dll-hell that is Xerces and JAXB inclusion in JRE. Here are the relevant bits: test.xsd: <xs:element name="document"> <xs:complexType> <xs:sequence> <xs:element name="duration" type="xs:duration" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> test.xml: <document xmlns="urn:test"> <duration>PT1H</duration> <duration> PT1H</duration> <duration>PT1H </duration> <duration> PT1H </duration> <duration> PT1H </duration> </document> Test.java: for (Duration duration : doc.getDuration()) if (duration != null) System.out.println("Got duration " + duration); else System.err.println("Got NULL duration!"); Ant output: [java] Got duration PT1H [java] Got NULL duration! [java] Got NULL duration! [java] Got NULL duration! [java] Got NULL duration!
        Hide
        Iaroslav Savytskyi added a comment -

        Hi, Joe,

        I think this is JAXP bug. As I see from the spec for the duration type it should do "whiteSpace = collapse (fixed)".

        Show
        Iaroslav Savytskyi added a comment - Hi, Joe, I think this is JAXP bug. As I see from the spec for the duration type it should do "whiteSpace = collapse (fixed)".

          People

          • Assignee:
            Unassigned
            Reporter:
            gturner
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: