SimpleXML deserialization error in Android

断了今生、忘了曾经 提交于 2020-01-03 12:11:10

问题


I have problem with deserialization java-object. For deserialization I use SimpleXML.

@Root
public class A {
    @ElementList
    private ArrayList<B> b;

    getters, setters...
}  


public class B{
    @Element(name="C", required=false)
    private C c;

    getters, setters...
}  

public class C{
    private int id;
    private String name;

    getters, setters...
}  

I receiving XML, which have next field:

<A>
   <B>
       <C i:nil="true" />
   </B>
</A>

Dalvink throws next exception: org.simpleframework.xml.core.AttributeException: Attribute 'nil' does not have a match in class B at line -1

Are there any ideas for solution? Thanks.


回答1:


you should add to your C class a property:

@Attribute(name = "i:nil")
boolean myProperty;



回答2:


Usually null content is presented with

xsi:nil="true"

attribute if that's what you're trying to do here.



来源:https://stackoverflow.com/questions/5536896/simplexml-deserialization-error-in-android

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