Reflecting on JAXB annotated objects, is there a way to determine if a class/field/method will result in a xsi:type attributed during marshaling?
Is XmlElement annotation,
annotation.type != javax.xml.bind.annotation.XmlElement.DEFAULT.class
the only case I need to worry about?
I’m writing a Lua unmarshaler where we have dropped much of the usual xml type info and I’m trying to figure-out how to match the incoming Lua to JAXB.
Thanks.
–Update–
Here is simple example that shows the problem:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement()
@XmlSeeAlso({ Cat.class, Dog.class })
public class Animal {
@XmlElement()
public List<Animal> critters;
@XmlAttribute
public String type;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement()
public class Dog extends Animal {
public Dog() {
this.type = "German Shepherd";
}
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement()
public class Cat extends Animal {
public Cat() {
this.type = "Black";
}
}
When I receive an Animal object can I query critter’s annotation to detect that it should be a Dog or Cat and not an Animal?
There are a couple circumstances where a JAXB (JSR-222) implementation will write out an xsi:type attribute.
Object(or is annotated with@XmlElement(type=Object.class)) and not mapped with@XmlAnyElement(lax=true)and holds an instance of an Object that theJAXBContexthas mappings for.xsi:typeattribute to represent subclasses (see: http://blog.bdoughan.com/2010/11/jaxb-and-inheritance-using-xsitype.html).