【发布时间】:2012-08-24 15:26:44
【问题描述】:
考虑到 JAXB 注释对象,有没有办法确定一个类/字段/方法是否会在编组期间产生 xsi:type 属性?
是XmlElement注解,annotation.type != javax.xml.bind.annotation.XmlElement.DEFAULT.class
我需要担心的唯一情况是什么?
我正在编写一个 Lua 解组器,我们在其中删除了许多常用的 xml 类型信息,我正在尝试弄清楚如何将传入的 Lua 与 JAXB 匹配。
谢谢。
--更新--
这是一个显示问题的简单示例:
@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";
}
}
当我收到一个 Animal 对象时,我可以查询 critter 的注释以检测它应该是 Dog 还是 Cat 而不是 Animal?
【问题讨论】:
标签: jaxb