This is the continuation of Ignore Unexpected XML with XStream. In the above code XStream parser declaration will ignore Unexpected XML. The below XStream parser declaration will be useful to Ignore Unexpected JSON.

XStream xstream = new XStream(new  JettisonMappedXmlDriver()) {
            @Override
            protected MapperWrapper wrapMapper(MapperWrapper next) {
                return new MapperWrapper(next) {
                    @Override
                    public boolean shouldSerializeMember(Class definedIn,
                            String fieldName) {
                        if (definedIn == Object.class) {
                            return false;
                        }
                        return super
                                .shouldSerializeMember(definedIn, fieldName);
                    }
                };
            }
        };

new  JettisonMappedXmlDriver()  // this driver is for generating JSON

Everything is same as before article.

0 comments:

Blogroll

Follow this blog by Email

Popular Posts