需要使用简单的api将xml响应反序列化为对象。当我反序列化一个对象时,我得到一个异常:在第1行的类java.lang.Object中,org.simpleframework.xml.core.ElementException:元素'Transducer‘没有匹配项
如果能提供我做错了什么的线索,或者是一个反序列化带有复杂对象的内联列表的工作示例,我将非常感激。
谢谢。
附件是我的对象的简化示例:
我的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>我的对象:
@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;
}我为每个属性添加了private、setter和getter,并通过写入进行了序列化
<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>我从my.xml反序列化得到异常,如下所示
org.simpleframework.xml.core.ElementException:元素“Transducer”在第1行的类java.lang.Object中没有匹配项
发布于 2015-03-24 17:02:23
您是否尝试过将属性设置为私有,并为每个属性创建getter和setter?
https://stackoverflow.com/questions/29228274
复制相似问题