[Simple-support] Attribute always returning null or 0
Brought to you by:
niallg
|
From: Shobhit S. <sho...@gm...> - 2012-05-25 20:05:37
|
Hello,
I am new to Simple Framework and have written a simple program to
deserialize an xml file to java objects using Simple. I am able to do
it partially but the attribute always return null or 0. The code and
the test xml is shown below:
Below is the class
file-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
import java.io.File;
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
public class Deserialize {
/**
* @param args
*/
//@Attribute(name="code" , required=false)
@Root
private String datadef;
@Element
private String str;
@Element
private String state;
@Attribute(name= "code",required=false)
private int code;
@Attribute(name="id", required=false)
private int id;
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Serializer serializer = new Persister();
File source = new File("importFiles/test.xml");
Deserialize deserialize = serializer.read(Deserialize.class, source);
System.out.println("Str : " + deserialize.str);
System.out.println("State : " + deserialize.state);
System.out.println("Code : " + deserialize.code);
System.out.println("Id : " + deserialize.id);
}
}
Below is the sample xml file I am trying to
deserialize-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<datadef>
<str>123</str>
<state code="100" id="4">test</state>
</datadef>
I am not able to understand what is the mistake I am doing. Thus
seeking for immediate help.
thanks and regards
--
Shobhit Sharda
MSc in SSE
RWTH Aachen University
Aachen
Germany
blog: http://shobhitsharda.wordpress.com
|