users@jaxb.java.net

Marshalling outputs XML with a duplicate element

From: Glen Verran <glen.verran_at_traderoot.com>
Date: Wed, 19 Mar 2008 10:48:55 +0200

Hi folks,
 
I have a XSD with the following element.
 
 <xs:element name="ListConfigurationIdentifiersRequest">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="echoData" type="xs:string"/>
      <xs:element name="identifierType" type="xs:string" minOccurs="0"/>
      <xs:element name="identifier" type="xs:string" minOccurs="0"/>
      <xs:element name="revision" type="xs:string" minOccurs="0"/>
     </xs:sequence>
  </xs:complexType>
  </xs:element>

I also defined global bindings as below
 
<xs:annotation>
  <xs:appinfo>
    <jaxb:globalBindings>
      <xjc:superClass name="JaxbInternalMsg"/>
      <xjc:serializable uid="10001"/>
      <jaxb:javaType name="java.util.Calendar" xmlType="xs:dateTime"
        parseMethod="javax.xml.bind.DatatypeConverter.parseDate"
        printMethod="javax.xml.bind.DatatypeConverter.printDate"/>
    </jaxb:globalBindings>
  </xs:appinfo>
</xs:annotation>

The class JaxbInternalMsg implements an Interface containing 5 methods
of which getEchoData and setEchoData are part of that interface. The
JaxbInternalMsg class therefore contains the 5 methods including
getEchoData and setEchoData. These methods don't do anything at all.
 
XJC generates JAXB classes with getEchoData and setEchoData methods that
override the mentioned methods in JaxbInternalMsg which is 100% correct.
 
I create a ListConfigurationIdentifiersRequest class and set the
relevant fields, including echoData which I've set to 12345.
 
When I Marshall the ListConfigurationIdentifiersRequest object, the XML
that is generated contains two <echoData>12345</echoData> elements.
 
Why is this so and how can I fix it? I cannot make this an abstract
class since other JAXB generated classes do not have echoData as an
element.
 
Pleaes help?
Thanks
~Glen