所以,我有两个类,都是另一个类的子类,我的XML可以是,也是由父类命名并由id属性标识。
如何让XStream解组到正确的类?
代码:
@XStreamAlias("Extension")
public class Extension {
@XStreamAsAttribute
@XStreamAlias("Id")
private String id;
@XStreamAsAttribute
@XStreamAlias("Required")
private boolean required;
/* getters and setters */
}
@XStreamAlias("Extension")
public class ULExtension extends Extension {
@XStreamAlias("ULData")
private ULData ULData;
/* getter and setter */
}
@XStreamAlias("Extension")
public class XTExtension extends Extension {
@XStreamAlias("ExtConverter")
private ExtConverter extConverter;
/* getter and setter */
}
进入的XML看起来像这样
<Extension Id="UL" Required="false"><ULData><stuffAndThings/></ULData></Extension>
或
<Extension Id="XT" Required="false"><ExtConverter><otherStuffAndThings/></ExtConverter></Extension>