public abstract class SBase {
@XStreamAsAttribute
String id="";
@XStreamAsAttribute
String name="";
@XStreamAsAttribute
String title="";
@XStreamAsAttribute
String enabled = "true";
@XStreamAsAttribute
String value="";
@XStreamAlias("text")
public class SText extends SBase {
@XStreamAsAttribute
private String validateRule ;
在使用xstream的继承关系是发现,父类的值可以被反序列化出来,但是子类的属性却无法赋值。
public static void main(String[] args) {
// XStream stream = new XStream(new DomDriver());
XStream stream = new XStream(new AnnotationJavaReflectionProvider());
stream.autodetectAnnotations(true);
stream.processAnnotations(SBase.class);
stream.processAnnotations(SText.class);
后来发现,必须要手动给每个类注册一下processAnnotations,在序列化的时候只需要一句autodetectAnnotations就可以搞定,反序列化却需要一个个类的制定。