答案 0 :(得分:2)
您需要为要忽略的类型编写自定义转换器。
例如,如果要忽略JLabel:
public class MyJLabelConverter implements Converter {
@Override
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
}
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
return null;
}
@Override
public boolean canConvert(Class clazz) {
return clazz.equals(JLabel.class);
}
}
并将其注册为:
xstream.registerConverter(new MyJLabelConverter());