Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 328646

Summary: @XmlElements and multiple @XmlElement with same type.
Product: z_Archived Reporter: Blaise Doughan <blaise.doughan>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Blaise Doughan CLA 2010-10-25 14:36:53 EDT
If a property is annotated with the following (note the two @XmlElement annotations associated with PhoneNumber.class):

    @XmlElements(value = { 
            @XmlElement(name="address", 
                        type=Address.class),
            @XmlElement(name="phone-number", 
                        type=PhoneNumber.class),
            @XmlElement(name="fax-number", 
                        type=PhoneNumber.class),
            @XmlElement(name="note", 
                        type=String.class)
    })
    public Object contactInfo;

MOXy can successfully unmarshal documents containing both "phone-number" and "fax-number" elements.  When it comes to the marshal operation MOXy must choose one of the elements to use.

In order to allow the user to specify the element name/namespace the property could be defined as type JAXBElement.  Currently this does not work.  This scenario also does not appear to work in the JAXB RI.

    @XmlElements(value = { 
            @XmlElement(name="address", 
                        type=Address.class),
            @XmlElement(name="phone-number", 
                        type=PhoneNumber.class),
            @XmlElement(name="fax-number", 
                        type=PhoneNumber.class),
            @XmlElement(name="note", 
                        type=String.class)
    })
    public JAXBElement<Object> contactInfo;
Comment 1 Eclipse Webmaster CLA 2022-06-09 10:34:59 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink