Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 328646 - @XmlElements and multiple @XmlElement with same type.
Summary: @XmlElements and multiple @XmlElement with same type.
Status: NEW
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: 2010-10-25 14:36 EDT by Blaise Doughan CLA
Modified: 2022-06-09 10:34 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 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