我尝试反序列化从SOAP请求返回的XML列表,但出现以下错误:
- com.fasterxml.Jackson.databind.JsonMappingException:[Source:]处的[simple type,class MyClassBLL]的重复属性“LstMyClassInfo”(String);行:1,列:1]*
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Getter
@Setter
@JsonPropertyOrder({"LstMyClassInfo", "DtIni", "DtEnd", "LstNumbers"})
public class MyClassBLL {
@JacksonXmlElementWrapper(localName = "LstMyClassInfo")
public List<MyClassInfo> MyClassInfoList;
public String DtIni;
public String DtFDtEndnal;
@JacksonXmlElementWrapper(localName = "LstNumbers")
public List<String> Numbers;
}
private MyClassBLL deserialize(String captureInformation) throws Exception {
JacksonXmlModule xmlModule = new JacksonXmlModule();
xmlModule.setDefaultUseWrapper(false);
ObjectMapper objectMapper = new XmlMapper(xmlModule);
return objectMapper.readValue(captureInformation, MyClassBLL.class);
}
这是要反序列化的XML示例:
<MyClassBLL xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<LstMyClassInfo>
<MyClassInfo>
<SNumber>XXXXXXXXX</SNumber>
-- Any other properties
</MyClassInfo>
<MyClassInfo>
<SNumber>YYYYYYYYY</SNumber>
-- Any other properties
</MyClassInfo>
<MyClassInfo>
<SNumber>ZZZZZZZZZ</SNumber>
-- Any other properties
</MyClassInfo>
</LstMyClassInfo>
<DtIni>2023-05-01T03:00:00</DtIni>
<DtEnd>2023-06-01T02:59:59</DtEd>
<LstNumbers>
<string>XXXXXXXXX</string>
<string>YYYYYYYYY</string>
<string>ZZZZZZZZZ</string>
</LstNumbers>
</MyClassBLL>
有人能帮帮我吗
PS:对不起,我的英语不好
我已经检查了JacksonXml文档,但我的实现似乎没有任何问题。
1条答案
按热度按时间tpxzln5u1#
您需要将
@JacksonXmlProperty
添加到MyClassBLL
类中与xml元素名称匹配的字段中。示例