Question

i'm deserializing a Xml file which is :

<?xml version="1.0" encoding="utf-8"?>
<UserList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <UserLists>
    <user>
      <username>Salesman1</username>
      <password>123</password>
      <salesmanId>4</salesmanId>
    </user>
  </UserLists>
</UserList>

with this line that throws me the Exception :

org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy @org.simpleframework.xml.ElementList(data=false, empty=true, entry=user, inline=true, name=, required=true, type=void) on field 'user' public java.util.List azdad.pos.android.UserList.user for class azdad.pos.android.UserList at line 2

my entity class is :

import java.util.List;

import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Path;
import org.simpleframework.xml.Root;

@Root(name="UserList",strict=false)

public class UserList{


     @ElementList(entry="user", inline=true)
     public List<UserInfo> user;

     public List<UserInfo> getUsrs(){
         return user;
     }
}

I've used

strict

to ignore the Tag According to this link :

How to ignore unused XML elements while deserializing a document?

but it doesn't work , does anybody know how can i ignore tag for deserializng

Was it helpful?

Solution

I believe what you're trying to ignore is <UserLists> tag right ? Your problem comes from using inline attribute (see Simple XML inlining), you need rather to use :

@Root(name="UserList")
public class UserList{


    @ElementList(name="UserLists", entry="user")
    public List<UserInfo> user;

    public List<UserInfo> getUsers(){
        return user;
    }
}

The strict attribute shouldn't be needed then.

Note : I corrected a syntax error in getUsers(): as Simple uses reflection, this might be important.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top