Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 366086 - Schema Gen Optimization - When property name matches root element name with anonymous complex type
Summary: Schema Gen Optimization - When property name matches root element name with a...
Status: CLOSED INVALID
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-08 13:57 EST by Blaise Doughan CLA
Modified: 2022-06-09 10:27 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Blaise Doughan CLA 2011-12-08 13:57:05 EST
When a class is annotated with both @XmlRootElement and @XmlType(name="") an incorrect schema is being generated for properties that refer to this type.  Currently MOXy is generating the element with an anonymous complex type, but it should be 

Customer

    @XmlRootElement
    @XmlType(name="")
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Customer {
	private Address address;
    }

Address

    @XmlRootElement
    @XmlType(name="")
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Address {
	private String street;
    }

Currently we generate the following XML schema:

   <?xml version="1.0" encoding="UTF-8"?>
   <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:element name="address">
         <xsd:complexType>
            <xsd:sequence>
               <xsd:element name="street" type="xsd:string" minOccurs="0"/>
            </xsd:sequence>
         </xsd:complexType>
      </xsd:element>
      <xsd:element name="customer">
         <xsd:complexType>
            <xsd:sequence>
               <xsd:element name="address" minOccurs="0">
                  <xsd:complexType>
                     <xsd:sequence>
                        <xsd:element name="street" type="xsd:string" minOccurs="0"/>
                     </xsd:sequence>
                  </xsd:complexType>
               </xsd:element>
            </xsd:sequence>
         </xsd:complexType>
      </xsd:element>
   </xsd:schema>

But we could generate, because in this case the element name for the property exactly matches the root element name for the Address class:

  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  <xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="address">
      <xs:complexType>
        <xs:sequence>
          <xs:element name="street" type="xs:string" minOccurs="0"/>
        </xs:sequence>
      </xs:complexType>
    </xs:element>
    <xs:element name="customer">
      <xs:complexType>
        <xs:sequence>
          <xs:element ref="address" minOccurs="0"/>
        </xs:sequence>
      </xs:complexType>
    </xs:element>
  </xs:schema>
Comment 1 Eclipse Webmaster CLA 2022-06-09 10:27:39 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink