Question

I'm trying to marshall a class that is extending abstract class using eclipseLink moxy:

public abstract class AbstractExample {
  private String fieldA;
  private String fieldB;

  // Getters, setters 
}

public class Example extends AbstractExample {
  private String fieldC;
  private String fieldD;

  // More fields, getters and setters
}

I use xml for mapping:

<java-type name="com.example.Example">
  <xml-root-element name="com.another.package.Example2" />
  <java-attributes>
    <!-- All fields defined here -->
  </java-attributes>
</java-type>

Now everything is fine when unmarshalling. Problem appears when I'm marshalling the object. Instead of

<com.another.package.Example2> 

root element I get only

<Example2> 

as root element. What's interesting - as soon as I push the fields from abstract class down into Example, and remove extends AbstractExample keywords, the root is what it should be

<com.another.package.Example2>.  

Am I doing something wrong? I really need to extend the abstract class or my code would have a lot of redundancy.

Was it helpful?

Solution

Note: I'm the EclipseLink JAXB (MOXy) lead.

This issue turned out to be the following MOXy bug:

This issue has now been fixed in the EclipseLink 2.3.3 and 2.4.0 streams. It will be available in the nightly downloads starting tomorrow (Feb 25, 2012):

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top