Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SimpleXML deserialization error in Android

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.

like image 775
Dmytro Boichenko Avatar asked Apr 04 '11 09:04

Dmytro Boichenko


2 Answers

you should add to your C class a property:

@Attribute(name = "i:nil")
boolean myProperty;
like image 179
Vladimir Ivanov Avatar answered Nov 19 '22 06:11

Vladimir Ivanov


Usually null content is presented with

xsi:nil="true"

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

like image 33
harism Avatar answered Nov 19 '22 04:11

harism