users@jaxb.java.net

Union with date and dateTime

From: Greg T Robertson <gregrob_at_us.ibm.com>
Date: Tue, 21 Oct 2003 10:15:51 -0400

I am an experiencing an issue with JAXB (from JWSDP-1.2) related to a
schema union, and am wondering if anyone has any ideas as to what may be
occurring. This problem originally occurred in a much larger schema, but I
have simplified it, to make things easier to discuss. The schema is this:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
      <xsd:element name="test" type="testType" />

      <xsd:complexType name="testType">
            <xsd:sequence>
                  <xsd:element name="firstName" type="xsd:string" />
                  <xsd:element name="height" type="xsd:decimal" />
                  <xsd:element name="birthTime" type="dateTimeAny" />
            </xsd:sequence>
      </xsd:complexType>

      <xsd:simpleType name="dateTimeAny">
            <xsd:union memberTypes="xsd:dateTime xsd:date" />
      </xsd:simpleType>
</xsd:schema>

The original XML file is this:

<?xml version="1.0" encoding="UTF-8"?>
<test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd">
  <firstName>firstName</firstName>
  <height>0.0</height>
  <birthTime>2001-12-31T12:00:00-05:00:00</birthTime>
</test>

With the dateTimeAny type declared as
<xsd:simpleType name="dateTimeAny">
      <xsd:union memberTypes="xsd:dateTime xsd:date" />
</xsd:simpleType>
everything works fine. I can unmarshal, marshall, repeatedly. Writing XML
each time between the unmarshal/marshal sequence, the output looks the same
e.g. the birthTime field looks like the original.

But if the dateTimeAny is declared as
<xsd:simpleType name="dateTimeAny">
      <xsd:union memberTypes="xsd:date xsd:dateTime" />
</xsd:simpleType>
then when I follow the same sequence after the first marshalling the
birthTime will look like this: "2001-12-31-05:00:00". Notice that the time
has disappeared.

While in this small example other than losing precision there are no other
side effects, with my original schema, which uses the same dateTimeAny
type, unmarshalling fails with an error related to an unexpected of date.

Has anyone else seen this behavior?


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net