Using Eclipselink/MOXy 2.3 i have following usecase in marshalling to XML:
abstract class MyAbstract {
}
class MyImpl extends MyAbstract {
}
class A {
private MyAbstract myAbstract;
// MyImpl is behind this
public MyAbstract getMyAbstract() {
return myAbstract;
}
}
I have following mapping defined in oxm.xml:
<java-type name="foo.MyAbstract" xml-accessor-type="NONE">
<xml-see-also>
foo.MyImpl
</xml-see-also>
</java-type>
<java-type name="foo.MyImpl">
<xml-root-element name="MyImpl" />
</java-type>
<java-type name="bar.A" xml-accessor-type="NONE">
<xml-root-element name="A" />
<java-attributes>
<xml-element java-attribute="myAbstract" type="foo.MyAbstract" />
</java-attributes>
</java-type>
Now this results in:
<A>
<myAbstract xsi:type="myImpl">
<!-- Mapped members of MyImpl + MyAbstract -->
</myAbstract>
</A>
Since i didnt want the property-name in the exported xml I changed:
<java-type name="bar.A" xml-accessor-type="NONE">
<xml-root-element name="A" />
<java-attributes>
<xml-element java-attribute="myAbstract" type="foo.MyAbstract" xml-path="."/>
</java-attributes>
</java-type>
which resulted in:
<A>
<!-- Members of MyImpl + MyAbstract marshalled without any wrapping element-->
</A>
What i want is:
<A>
<MyImpl>
<!-- Members of MyImpl + MyAbstract -->
</MyImpl>
</A>
The question is: how do i achieve this? MOXy is just ignoring my XmlRootElement on MyImpl...
EDIT:
Trying what Blaise suggested gives me following exception:
Exception [EclipseLink-60] (Eclipse Persistence Services - 2.3.2.v20111125-r10461):
org.eclipse.persistence.exceptions.DescriptorException
The method [] or [getMyAbstract] is not defined in the object [bar.A].
Now this needs further information which i had left out before because i thought it was not relevant:
Class A is an interface which defines: public X getMyAbstract();
MyAbstract implements X (this is why i added the type-attribute in the mapping for interface A).
So, using xml-element-ref
MOXy does not "see" the getter anymore, using xml-element
it does.