我有以下 XML:
<licenseSummary>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.4</version>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
</dependency>
<dependency>
<groupId>somegroup</groupId>
<artifactId>someartifact</artifactId>
<version>2.43.0-SNAPSHOT</version>
<licenses>
<!--No license information available. -->
</licenses>
</dependency>
</dependencies>
</licenseSummary>
当尝试反序列化此 XML-File Jackson 时失败,因为<licenses />
第二个<dependency />
-Element 的部分中有注释而不是元素,并出现以下错误:
Cannot deserialize instance of `java.util.ArrayList` out of VALUE_STRING token
我尝试配置XMLMapper
with 但这无济于事:
ObjectMapper xmlMapper = new XmlMapper();
xmlMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
这是相关 POJO 的样子:
public class Dependency {
private String groupId;
private String artifactId;
private String version;
private List<License> licenses = new ArrayList<License>(1);
public String getGroupId() {
return groupId;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
}
public String getArtifactId() {
return artifactId;
}
public void setArtifactId(String artifactId) {
this.artifactId = artifactId;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public List<License> getLicenses() {
return licenses;
}
public void setLicenses(List<License> licenses) {
this.licenses = licenses;
}
}
有谁知道我怎么能忽略评论。(顺便说一句:我无法删除 XML 文件中的注释)
jackson-dataformat-xml
版本 2.9.4