The mapping that you are looking for is XmlElementRef . This corresponds to the concept of substitution groups in XML schema.
Up vote 1 down vote favorite share g+ share fb share tw.
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: foo. MyImpl Now this results in: Since I didn't want the property-name in the exported xml I changed: which resulted in: What I want is: 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. Inheritance jaxb eclipselink moxy link|improve this question edited Jan 16 at 13:45 asked Jan 13 at 16:29quaylar7977 83% accept rate.
– Blaise Doughan Jan 16 at 13:18 @BlaiseDoughan: I have no mapping for the concrete class - just the one for the interface bar.A. Since I am passing in just the interface, I figured it would be sufficient to just have a mapping for the interface? I followed the first example in blog.bdoughan.com/2011/05/….
– quaylar Jan 16 at 13:33 In that example assuming the interface A corresponds to the Customer interface in my example, you will need to still bootstrap and map the JAXBContext on the impl class, CustomerImpl in my example. – Blaise Doughan Jan 16 at 13:46 @BlaiseDoughan - Is it sufficient to add an entry to oxm. Xml for my Impl class and bootstrap JAXBContext with a Map containing package-name -> oxm.
Xml entries? This is how I am bootstrapping it now - I am just missing an entry for the Impl class. And what should this entry look like?
I already mapped everything for the interface..? – quaylar Jan 16 at 14:02 1 I opened and fixed the following bug based on our "chat": bugs.eclipse.org/368746. You can try out the fix by downloading a 2.3.3 nightly build from the following location: eclipse.org/eclipselink/downloads/nightly.php – Blaise Doughan Jan 16 at 20:14.
The mapping that you are looking for is @XmlElementRef. This corresponds to the concept of substitution groups in XML schema. Bar/oxm.
Xml Below is the external mapping document for the bar package. Note how the myAbstract property is mapped with xml-element-ref which is the XML representation of @XmlElementRef foo/oxm. Xml Below is the external metadata file for the foo package: foo.
MyImpl Demo Below is demo code for this example: package forum8853855; import java.util. *; import javax.xml.bind. *; import org.eclipse.persistence.jaxb.
JAXBContextFactory; import bar. A; import foo. MyImpl; public class Demo { public static void main(String args) throws Exception { List oxm = new ArrayList(2); oxm.
Add("foo/oxm. Xml"); oxm. Add("bar/oxm.
Xml"); Map properties = new HashMap(1); properties. Put(JAXBContextFactory. ECLIPSELINK_OXM_XML_KEY, oxm); JAXBContext jc = JAXBContext.
NewInstance(new Class {A. Class}, properties); Marshaller marshaller = jc. CreateMarshaller(); marshaller.
SetProperty(Marshaller. JAXB_FORMATTED_OUTPUT, true); A a = new A(); a. SetMyAbstract(new MyImpl()); marshaller.
Marshal(a, System. Out); } } Output For More Information http://blog.bdoughan.com/2010/11/jaxb-and-inheritance-using-substitution.html http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html.
1 Thanks for supporting MOXy tag ;) – dma_k Jan 14 at 0:06 Thanks Blaise for the tip, I had actually already tried this before I posted (acc. To your blog-post on this topic) but an exception occurred during marshalling. I will edit my post above with some additional information.
– quaylar Jan 16 at 12:04 @quaylar - In your update can you include the exception you are seeing? – Blaise Doughan Jan 16 at 12:06.
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.