问题描述
<Message>
<Id>12345</Id>
<StatusMessage>
<Status>random status</Status>
<MessageDetail>random message detail</MessageDetail>
</StatusMessage>
<Properties>
<Property>
<Key>key1</Key>
<Value>value1</Value>
</Property>
<Property>
<Key>key2</Key>
<Value>value2</Value>
</Property>
</Properties>
</Message>
我的对象是:
@JacksonXmlRootElement
public class Message {
@JacksonXmlProperty(localName = "Id")
private String id;
@JacksonXmlProperty(localName = "Properties")
private Properties properties;
}
public class Properties {
@JacksonXmlProperty(localName = "Property")
private Map<String,String> property;
}
public class Property {
@JacksonXmlProperty(localName = "key")
private String key;
@JacksonXmlProperty(localName = "value")
private String value;
}
public class StatusMessage {
@JacksonXmlProperty(localName = "Status")
private String status;
@JacksonXmlProperty(localName = "MessageDetail")
private String messageDetail;
}
然后我的主要代码只是使用jackson尝试反序列化xml字符串:
public void deserialize(String xmlString) {
Message message = getXmlMapper().readValue(xmlString,Message.class);
...
}
在我的测试中,我基本上获得了成功,但是唯一会通过地图的是它在XML中看到的最后一个属性。我相信它可能会覆盖以前的那些,因此在此示例中,它将在对象中返回一个映射,该映射具有key2的键和value2的值。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)