在使用xstream反序列化时遇到的问题

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就可以搞定,反序列化却需要一个个类的制定。

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值