Sivaguru Jambulingam
Sivaguru Jambulingam

Reputation: 319

ValueRequired Exception While using Simple-XML-Framework

I am trying to use Simple-XML-framework. But i am getting ValueRequiredException

org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy @org.simpleframework.xml.ElementList(data=false, empty=true, entry=, inline=false, name=, required=true, type=void) on field 'Employees' public java.util.List com.example.xmlparsing.Company.Employees for class com.example.xmlparsing.Company at line 2

My XML file has the following content :

<?xml version="1.0" encoding="utf-8"?>
<Company>
<Emp>
    <Name>Venkat</Name>
    <ID>661511</ID>  
</Emp>
<Emp>
    <Name>Shiv</Name>
    <ID>661311</ID> 
</Emp>
</Company>

My Annotation classes are as follows :

Company.java :

package com.example.xmlparsing;

import java.util.List;

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

@Root
public class Company {

@ElementList
public List<Emp> Employees;

}

Emp.java :

package com.example.xmlparsing;

import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.Text;

@Element(name="Emp")
public class Emp {

@Element
public String Name;

@Element
public String ID;


}

What could be the problem? how to fix it?

Upvotes: 5

Views: 4951

Answers (1)

ollo
ollo

Reputation: 25380

There are two things wrong in your Code:

First, you need @Root() instead of @Element at Emp class:

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

@Element
public String Name;

@Element
public String ID;


}

Second, if you use a list that way:

@Root
public class Company {

@ElementList
public List<Emp> Employees;

}

its wrapped into another xml tag.
You can either change your xml or simply use @ElementList(inline = true).

Upvotes: 9

Related Questions