Up vote 1 down vote favorite share g+ share fb share tw.
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, properties jaxb eclipselink moxy inherited link|improve this question edited Jan 10 at 7:16 asked Jan 5 at 7:51quaylar7977 83% accept rate.
There is nothing special you need to do: B I have modified the B class based on one of your previous questions in order to populate the x property: package forum8739246; public class B extends A { private Foo x; public B() { x = new Foo(); } public Foo getX() { return this. X; } } oxm. Xml Below is the metadata file that I based on your comments to my original answer.
Demo package forum8739246; import java.util. HashMap; import java.util. Map; import javax.xml.bind.
*; import javax.xml.namespace. QName; import org.eclipse.persistence.jaxb. JAXBContextFactory; public class Demo { public static void main(String args) throws Exception { Map properties = new HashMap(1); properties.
Put(JAXBContextFactory. ECLIPSELINK_OXM_XML_KEY, "forum8739246/oxm. Xml"); JAXBContext jc = JAXBContext.
NewInstance(new Class {C. Class},properties); System.out. Println(jc.getClass()); Marshaller marshaller = jc.
CreateMarshaller(); marshaller. SetProperty(Marshaller. JAXB_FORMATTED_OUTPUT, true); JAXBElement be = new JAXBElement(new QName("b"), B.
Class, new B()); marshaller. Marshal(b, System. Out); JAXBElement c = new JAXBElement(new QName("c"), C.
Class, new C()); marshaller. Marshal(c, System. Out); } } Output As can be seen from the output the x property is marshalled for both instances of B and C: class org.eclipse.persistence.jaxb.JAXBContext.
Using oxm. Xml and accessor-type FIELD for class B, marshalling 'x' using an I am getting: Ignoring attribute x on class C as no Property was generated for it. – quaylar Jan 9 at 12:58 The issue you are seeing could be related to the following bug (bugs.eclipse.org/367886).
I still haven't been able to reproduce the issue you are seeing. I have updated my answer to reflect the latest code I have tried. – Blaise Doughan Jan 9 at 17:48 Blaise, I had left out the abstract declaration of getX() in A, which was overriden in B.
I guess now you should be able to reproduce this issue - see my first post for an update to the class declaration... – quaylar Jan 10 at 7:18.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.