Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Jackson将XML反序列化为映射_Java_Xml_Jackson Dataformat Xml - Fatal编程技术网

Java 使用Jackson将XML反序列化为映射

Java 使用Jackson将XML反序列化为映射,java,xml,jackson-dataformat-xml,Java,Xml,Jackson Dataformat Xml,我有一个XML文件,看起来像: <Message> <Id>12345</Id> <StatusMessage> <Status>random status</Status> <MessageDetail>random message detail</MessageDetail> </StatusMessage> <Properties>

我有一个XML文件,看起来像:

<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>
在我的测试中,我基本上取得了成功,但唯一能在地图上看到的是它在XML中看到的最后一个属性。我相信它可能会覆盖前面的内容,因此在本例中,它将在对象中返回一个带有键2和值2的映射

@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;
}
public void deserialize(String xmlString) {
  Message message = getXmlMapper().readValue(xmlString, Message.class);

  ...
}