Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty text is ignored in @JacksonXmlText #565

Open
aarcangeli opened this issue Jan 4, 2023 · 0 comments
Open

Empty text is ignored in @JacksonXmlText #565

aarcangeli opened this issue Jan 4, 2023 · 0 comments

Comments

@aarcangeli
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant