欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

XStream: UnknownFieldException - No such field

程序员文章站 2022-05-29 22:50:40
...

解决办法重写wrapMapper方法

return new XStream() {  
            @Override  
            protected MapperWrapper wrapMapper(MapperWrapper next){  
                return new MapperWrapper(next) {  
                    @Override  
                    public boolean shouldSerializeMember(Class definedIn, String fieldName){  
                        if (definedIn == Object.class){  
                            try {  
                                return this.realClass(fieldName) != null;  
                            } catch (Exception e){  
                                return false;  
                            }  
                        } else {  
                            return super.shouldSerializeMember(definedIn, fieldName);  
                        }  
                    }  
                };  
            }  
        };