I have following use-case for marshalling a POJO to XML using Eclipselink MOXy 2.3:
public abstract class A {
public abstract getX();
}
public class B extends A {
private Foo x;
@Override
public Foo getX() {
return this.x;
}
}
public class C extends B {
// Various fields and properties here
}
I need to marshal B and C but not A.
So i set A to be transient which makes B inherit all its members that will be marshalled when marshalling B.
I cant set B to be transient since i need to marshal it by itself, but when i marshal C, i need property B.getX() to be marshalled as well.
Is there any way other than @Override getX() in C to have it marshalled? At the moment it is just one property for which i need to do this, but imagine a large B class with many members, which one would need to @Override in C to marshal them together with C.
Is there any annotation or possibility in the external mapping file to mark a property in a superclass to be inherited by its immediate subclass (or all subclasses)?
What is the Eclipselink/JAXB way to go here?
Regards,
There is nothing special you need to do:
B
I have modified the
Bclass based on one of your previous questions in order to populate thexproperty:oxm.xml
Below is the metadata file that I based on your comments to my original answer.
Demo
Output
As can be seen from the output the x property is marshalled for both instances of
BandC: