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

Bug 355544

Summary: @XmlElementRef should support not specifying a name for abstract type with @XmlRootElements
Product: z_Archived Reporter: Paul Fullbright <paul.fullbright>
Component: EclipselinkAssignee: Denise Smith <denise.mahar>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: blaise.doughan, denise.mahar, eclipselink.oxm-inbox
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Paul Fullbright CLA 2011-08-23 13:52:50 EDT
For the following object model:

@XmlRootElement(name="root")
public class Root {
		
	@XmlElementRef(type=Foo.class)
	public List foos;
}

@XmlSeeAlso({ FooA.class, FooB.class })
public abstract class Foo {
	
	@XmlValue
	public String value;
}

@XmlRootElement(name="foo-a")
public class FooA extends Foo {}

@XmlRootElement(name="foo-b")
public class FooB extends Foo {}


when attempting to marshal a document, I get the following exception:

javax.xml.bind.JAXBException: 
Exception Description: Invalid XmlElementRef on property foos on class jaxbtest.model.Root. Referenced Element not declared.
...

This is pretty much Example 1 (Ant Task example) (except the type is specified in the @XmlElementRef annotation, not the java field) in the @XmlElementRef javadocs, and is fully supported with Metro.
Comment 1 Denise Smith CLA 2011-09-15 14:07:05 EDT

*** This bug has been marked as a duplicate of bug 355970 ***
Comment 2 Paul Fullbright CLA 2011-09-15 14:12:43 EDT
Is this really a duplicate?  The problem with the other use case was that the JAXB context wasn't including other types (I think).

Here there is an error if the user doesn't specify a name, which isn't used anyway.
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:04:56 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:09:51 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink