Categories
Mastering Development

Nested Classes with Same Name

I have an xsd schema which I converted to POJO using the xjc tool. The schema has nested complexTypes with same name but different attributes and elements.

So, I ended up with a class like

public class MyObject {
   // some variables
   public static Extension {
      private String A;
      private String B;
      public static Extension {
         private int X;
         private String Y;
      }
   }
}

Here snippet of the xsd

<xsd:complexType name="MyObject_Type">
    <xsd:sequence>
       <xsd:element name="abc" type="xsd:string"/>
       <xsd:element name="Extension" minOccurs="0">
          <xsd:complexType>
             <xsd:sequence>
                <xsd:element name="A" type="xsd:string"/>
                <xsd:element name="B" type="xsd:string"/>
                <xsd:element ref="Extension" minOccurs="0"/>
             </xsd:sequence>
          </xsd:complexType>
       </xsd:element>
    </xsd:sequence>
</xsd:complexType>
<xsd:element name="Extension" minOccurs="0">
   <xsd:complexType>
      <xsd:sequence>
         <xsd:element name="X" type="xsd:int"/>
         <xsd:element name="Y" type="xsd:string"/>
      </xsd:sequence>
   </xsd:complexType>
</xsd:element>

As you can see Extension is nested.

Is there a way of converting an xsd like this without running into duplicate class compilation error?

Thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *