Reputation: 97
need to deserialize an xml response to an object, using simple api. When I deserialize an object, , I get an exception: org.simpleframework.xml.core.ElementException: Element 'Transducer' does not have a match in class java.lang.Object at line 1
would appreciate a clue on what I am doing wrong or a working example for deserializing an inline list with complex objects.
Thanks.
Attached is a simplified example of my objects:
my xml:
<?xml version="1.0"?>
<Profile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Transducers>
<Transducer Value="0" Name="nDate" Unit="" ChineseName="时间" IsVisibility="true" Formatter="yyyyMMddHHmm" MessageLength="12" />
<Transducer Value="0" Name="EnvirTemp" Unit="℃" ChineseName="环温" IsVisibility="true" Formatter="0.0" MessageLength="4" />
<Transducer Value="0" Name="EnvirHumid" Unit="%RH" ChineseName="环湿" IsVisibility="true" Formatter="0.0" MessageLength="4" />
</Transducers>
<MMX>
<Transducers>
<Transducer Value="0" Name="aa" Unit="" ChineseName="a" IsVisibility="true" Formatter="0.0" MessageLength="4" />
<Transducer Value="0" Name="bb" Unit="" ChineseName="a" IsVisibility="true" Formatter="0.0" MessageLength="4" />
</Transducers>
</MMX>
</Profile>
my objects:
@Root
public class Profile {
@ElementList(entry="Transducer")
public List<Transducer> Transducers;
@ElementList
public List<List<Transducer>> MMX;
}
@Element
public class Transducer {
@Attribute
public double Value;
@Attribute
public String Name;
@Attribute
public String Unit;
@Attribute
public String ChineseName;
@Attribute
public boolean IsVisibility;
@Attribute
public String Formatter;
@Attribute
public String MessageLength;
}
I had add private and setter and getter for each property and I had serialized by write
<profile>
<CreateDate>2015-3-25</CreateDate>
<Id>1</Id>
<Name>pc4</Name>
<RecorderId>00000</RecorderId>
<Transducers class="java.util.ArrayList">
<Transducer ChineseName="温度" Formatter="0.0" Unit="C" MessageLength="4" Name="Temperature1" IsVisibility="true" Value="0.0"/>
<Transducer ChineseName="温度2" Formatter="0.0" Unit="C" MessageLength="4" Name="Temperature2" IsVisibility="true" Value="0.0"/>
</Transducers>
</profile>
I deseriized from my.xml that I get exception like
org.simpleframework.xml.core.ElementException: Element 'Transducer' does not have a match in class java.lang.Object at line 1
Upvotes: 0
Views: 281
Reputation: 1
Have you tried to make your properties private and create getter and setter for each of them?
Upvotes: 0