xml中存在节点,而model中不存在,就会报错:
com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$UnknownFieldException: No such field com.creditharmony.adapter.model.crif.CrifBodyAppVar.App_amt
-------------解决方案----------
重写XStream中的方法:
package com.creditharmony.adapter.core.service; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.xml.DomDriver; import com.thoughtworks.xstream.mapper.MapperWrapper; public class XStreamEx extends XStream { public XStreamEx(DomDriver domDriver) { super(); } @Override protected MapperWrapper wrapMapper(MapperWrapper next) { return new MapperWrapper(next) { @Override public boolean shouldSerializeMember(@SuppressWarnings("rawtypes") Class definedIn, String fieldName) { if (definedIn == Object.class) { return false; } return super.shouldSerializeMember(definedIn, fieldName); } }; } }
使用:
直接new对象即可.
XStreamEx xstream = new XStreamEx(new DomDriver(Constant.DEFAULT_CHARSET));