Hi, I'm trying to parse an xml file like this:
<?xml version='1.0'?>
<replacements xml:space='preserve' incomplete_format='false'>
<replacement offset='106' length='8'> </replacement>
</replacements>
This xml is generated by clang-format -output-replacements-xml, so it is critical that whitespaces are correctly parsed as string values.
However, when I parse it with XmlMapper, the returned value is null
assertEquals(" ", response.replacements[0].value) // value is null
My setup
build.gradle.kts:
dependencies {
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.14.1")
}
@JacksonXmlRootElement(localName = "replacements")
public class ClangFormatResponse {
public static ClangFormatResponse unmarshal(@NotNull String stdout) {
try {
XmlMapper xmlMapper = new XmlMapper();
return xmlMapper.readValue(stdout, ClangFormatResponse.class);
}
catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
@JacksonXmlProperty(localName = "space", isAttribute = true)
public String space;
@JacksonXmlProperty(localName = "incomplete_format", isAttribute = true)
public boolean incompleteFormat;
@JacksonXmlProperty(localName = "replacement")
@JacksonXmlElementWrapper(useWrapping = false)
public final List<ClangFormatReplacement> replacements = new ArrayList<>();
}
public class ClangFormatReplacement {
@JacksonXmlProperty(isAttribute = true)
public int offset;
@JacksonXmlProperty(isAttribute = true)
public int length;
@JacksonXmlText(false)
public String value;
}
My debug
From my analysis, I found that the text value is ignored due to this check
Hi, I'm trying to parse an xml file like this:
This xml is generated by
clang-format -output-replacements-xml, so it is critical that whitespaces are correctly parsed as string values.However, when I parse it with XmlMapper, the returned value is null
My setup
build.gradle.kts:
My debug
From my analysis, I found that the text value is ignored due to this check