How to ignore unused XML elements while deserializing a document?

大兔子大兔子 提交于 2019-11-30 10:46:13

Set strict to false within the Root annotation to ignore any XML elements or attributes that do not appear in the class.

@Root(strict=false)

Alternatively, set strict to false when you read the xml in the serialiser:

Root root = serializer.read(Root.class, source, false);

you can add (required=false) to a single element

@Element(required=false)
private int statusCode;

if you have more elements use

 @Root(strict=false)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!