Community
Participate
Working Groups
The following code produces: <zoo><Dog/><Cat/></zoo> but should produce: <zoo><dog/><cat/></zoo> import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.ArrayList; import java.util.List; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; import javax.xml.bind.annotation.XmlAnyElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement class Zoo { @XmlElementWrapper @XmlAnyElement(lax = true) private List<Animal> animals; public static void main(String[] args) throws Exception { Zoo zoo = new Zoo(); zoo.animals = new ArrayList<Animal>(); zoo.animals.add(new Dog()); zoo.animals.add(new Cat()); JAXBContext jc = JAXBContext.newInstance(Zoo.class, Dog.class, Cat.class); System.out.println(jc); Marshaller marshaller = jc.createMarshaller(); ByteArrayOutputStream os = new ByteArrayOutputStream(); marshaller.marshal(zoo, os); System.out.println(os.toString()); Unmarshaller unmarshaller = jc.createUnmarshaller(); Zoo unmarshalledZoo = (Zoo) unmarshaller .unmarshal(new ByteArrayInputStream(os.toByteArray())); if (unmarshalledZoo.animals == null) { System.out.println("animals was null"); } else if (unmarshalledZoo.animals.size() == 2) { System.out.println("it worked"); } else { System.out.println("failed!"); } } public interface Animal { } @XmlRootElement public static class Dog implements Animal { } @XmlRootElement public static class Cat implements Animal { } }
Created attachment 182221 [details] MOXy - Test Cases
Created attachment 182224 [details] MOXy - Fix After some investigation this problem only appears to occur on inner classes. We derive the class name by taking everything after the last '.'. When we called getQualifiedName on the class inner class names were being returned with a '$' in the class name. This has been resolved by using getRawName instead.
Fix checked into trunk at rev: 8462 Code reviewed by Matt MacIvor
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink