users@jaxb.java.net

Problem with xs:any

From: Martinescu, Eduard <Eduard.Martinescu_at_GlobalCrossing.com>
Date: Wed, 17 Jun 2009 17:32:17 +0000

The behavior of the Unmarshaller has changed between version 2.1.9 and 2.1.10
with regard to how it handles XmlAny unmarshalling.

For example. Given the following XSD snippet:
 <complexType>
   <complexContent>
      <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
        <sequence>
          <any/>
        </sequence>
        <attribute name="version" use="required">
          <simpleType>
            <restriction base="{http://www.w3.org/2001/XMLSchema}string">
              <enumeration value="1.0"/>
            </restriction>
          </simpleType>
        </attribute>
      </restriction>
    </complexContent>
  </complexType>

And an appropriate definition for an element named 'request', the following XML
will result in an element with an Array<Object> of 'content' and a string version.

Given the following XML:
<?xml version="1.0" encoding="utf-8"?>
<ATfES version="1.0">
 <request action="AppointmentSearch">
  <appointmentRequest id="228" type="V"
bookingIdent="6dd7f31b-38e7-46ee-97b5-c6eb547136ff" bookedAsGroup="false"
templateId="10" hasPermission="true">
   <name>541913/7 Voice/Dedicated Voice - xxx INC</name>
   <orgClass id="3">
    <name>EON</name>
   </orgClass>
   <timeZone id="5">GMT</timeZone>
   <duration type="N">120</duration>
   <confirmationRqd>true</confirmationRqd>
   <resource id="44" booked="false">
    <name>Turnup Pool</name>
    <type>O</type>
    <state>A</state>
    <email />
    <phone />
    <timeZone id="5">GMT</timeZone>
    <attendance>R</attendance>
    <responseRequested>true</responseRequested>
    <response>N</response>
    <resource id="23" booked="true">
     <name>xxx, xxx xxx</name>
     <type>P</type>
     <state>A</state>
     <email>xxx.xxx_at_xxx.xxx</email>
     <phone />
     <timeZone id="5">GMT</timeZone>
     <attendance>R</attendance>
     <responseRequested>true</responseRequested>
     <response type="A">A</response>
     <responseDTm userId="AMS\xxx">2006-10-31T17:23:22.053</responseDTm>
     <notificationDTm userId="AMS\xxx">2006-10-31T17:23:22.570</notificationDTm>
    </resource>
   </resource>
   <UDF ident="1">541913/7</UDF>
   <createDTm userId="AMS\xxx" name="xxx, xxx xxx"
email="xxx.xxx_at_xxx.xxx">2006-10-31T17:22:32.833</createDTm>
   <modifyDTm userId="AMS\xxx" name="xxx, xxx xxx"
email="xxx.xxx_at_xxx.xxx">2006-10-31T17:23:22.040</modifyDTm>
   <appointment id="209" future="false">
    <state>A</state>
    <startDTm>2006-11-01T04:00:00</startDTm>
    <endDTm>2006-11-01T06:00:00</endDTm>
    <confirmed autoConfirmed="false">false</confirmed>
   </appointment>
  </appointmentRequest>
  <pageInfo pageNumber="1" pageSize="500" pageCount="1" rowCount="50" />
  <status type="I" ident="100000">Success.</status>
 </request>
</ATfES>


I get back an element with version set to "1.0", and content to be an array of
objects. In version of JAXB prior to 2.1.10, the content array would actually
consist of 2 elements, an 'ApointmentRequest' object, and a String "\n".

With 2.1.10, the content array is now 3 elements. The first element in the
array is now a String "\n " (newline with space), then the 'AppointmentRequest'
then another String "\n"

I think this is wrong...and it has definitely broken code that was relying upon
the first (and should probably be only ) element in the content array to be the
AppointmentRequest object.

I've opened a bug report (https://jaxb.dev.java.net/issues/show_bug.cgi?id=646) but have had no responses to the bug yet, so I thought I would try here also.