1 Reply Latest reply on Feb 23, 2007 4:19 AM by James Christian

    JAXB error when using different derived types in the same co

    James Christian Newbie

      I have what seems to be a correct piece of SOAP being sent to JBossWS 1.0.4 that causes a binding exception. This only occurs when I send 2 different sub-class/derived types in the same container type. Sending each type independently (or several instances of the same type) works fine.

      In my example I have a Transaction type that contains an unbound number of Atoms, where Atom is an abstract type. There are 2 derivative of Atom, AtomType1 and AtomType2 which each extend Atom and add an additional sub-element element unique to the specialised type.

      (You can assume the namespaces/jax-rpc mapping is correct as when used independently from each other, the derived types bind fine.)

      My Types...

      <complexType abstract="true" name="Atom">
       <sequence>
       <element name="atom_id" type="nonNegativeInteger" />
       <element name="name" nillable="true" type="string" />
       </sequence>
      </complexType>
      
      <complexType name="Transaction">
       <sequence>
       <element maxOccurs="unbounded" name="atom" type="myns:Atom" />
       </sequence>
      </complexType>
      
      
      <complexType name="AtomType1">
       <complexContent>
       <extension base="myns:Atom">
       <sequence>
       <element name="atom_type_1_value" type="unsignedLong" />
       </sequence>
       </extension>
       </complexContent>
      </complexType>
      
      <complexType name="AtomType2">
       <complexContent>
       <extension base="myns:Atom">
       <sequence>
       <element name="atom_type_2_value" type="unsignedLong" />
       </sequence>
       </extension>
       </complexContent>
      </complexType>




      First example which is processed fine, and proves the type is bound correctly. Single Atom in the Transaction

      <?xml version="1.0" encoding="UTF-8"?>
       <env:Envelope
       xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
       xmlns:ns0="http://mynamespace">
      
       <env:Body>
       <ns0:update>
       <Transaction_1>
      
       <atom xmlns:ans1="http://mynamespace" xsi:type="ans1:AtomType2">
       <atom_id>1</atom_id>
       <name>myName2</name>
       <atom_type_2_value>2</atom_type_2_value>
       </atom>
      
       </Transaction_1>
       </ns0:update>
       </env:Body>
       </env:Envelope>



      The next Transaction contains 2 different Atom derived types, and fails processing with this exception
      Error:
      org.jboss.ws.binding.BindingException: org.jboss.ws.jbossxb.UnmarshalException: Failed to parse source: Requested element atom_type_2_value is not allowed in this position in the sequence. A model group with minOccurs=1 that doesn't contain this element must follow.


      <?xml version="1.0" encoding="UTF-8"?>
       <env:Envelope
       xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
       xmlns:ns0="http://mynamespace">
      
       <env:Body>
       <ns0:update>
       <Transaction_1>
      
       <atom xmlns:ans1="http://mynamespace" xsi:type="ans1:AtomType1">
       <atom_id>1</atom_id>
       <name>myName</name>
       <atom_type_1_value>2</atom_type_1_value>
       </atom>
      
       <atom xmlns:ans1="http://mynamespace" xsi:type="ans1:AtomType2">
       <atom_id>2</atom_id>
       <name>myName2</name>
       <atom_type_2_value>2</atom_type_2_value>
       </atom>
      
       </Transaction_1>
       </ns0:update>
       </env:Body>
       </env:Envelope>




      Just for a test, I switched the order of the Atoms in the transaction and note that the binding exception is now accredited to the other derived type

      Error:
      org.jboss.ws.binding.BindingException: org.jboss.ws.jbossxb.UnmarshalException: Failed to parse source: Requested element atom_type_1_value is not allowed in this position in the sequence. A model group with minOccurs=1 that doesn't contain this element must follow.



      <?xml version="1.0" encoding="UTF-8"?>
       <env:Envelope
       xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
       xmlns:ns0="http://mynamespace">
      
       <env:Body>
       <ns0:update>
       <Transaction_1>
      
       <atom xmlns:ans1="http://mynamespace" xsi:type="ans1:AtomType2">
       <atom_id>1</atom_id>
       <name>myName</name>
       <atom_type_1_value>2</atom_type_1_value>
       </atom>
      
       <atom xmlns:ans1="http://mynamespace" xsi:type="ans1:AtomType1">
       <atom_id>2</atom_id>
       <name>myName2</name>
       <atom_type_2_value>2</atom_type_2_value>
       </atom>
      
       </Transaction_1>
       </ns0:update>
       </env:Body>
       </env:Envelope>




      The final Transaction contains 2 atoms of the same derived type - and is processed fine.

      <?xml version="1.0" encoding="UTF-8"?>
       <env:Envelope
       xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
       xmlns:ns0="http://mynamespace">
      
       <env:Body>
       <ns0:update>
       <Transaction_1>
      
       <atom xmlns:ans1="http://mynamespace" xsi:type="ans1:AtomType1">
       <atom_id>1</atom_id>
       <name>myName</name>
       <atom_type_1_value>2</atom_type_1_value>
       </atom>
      
       <atom xmlns:ans1="http://mynamespace" xsi:type="ans1:AtomType1">
       <atom_id>2</atom_id>
       <name>myName2</name>
       <atom_type_2_value>2</atom_type_2_value>
       </atom>
      
       </Transaction_1>
       </ns0:update>
       </env:Body>
       </env:Envelope>




      Worth raising a bug?

      Regards - J