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

Xsi nil in collection fails to deserialize #353

Closed
ivarm1984 opened this issue Aug 12, 2019 · 2 comments
Closed

Xsi nil in collection fails to deserialize #353

ivarm1984 opened this issue Aug 12, 2019 · 2 comments

Comments

@ivarm1984
Copy link

I can't deserialize xsi:nil in collections. I use jackson 2.9.8

Sample test to reproduce it:

`class NilTest {

@Test
void shouldDeserialize() throws IOException {
    String xml = "" +
            "<A>" +
            "  <c xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='true'/>" + // no problems with this one
            "  <e>ee</e>" +
            "  <B>" +
            "    <d>dd</d>" +
            "  </B>" +
            "  <B>" +
            "    <d xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='true'/>" + // fails in collections
            "    <f>ff</f>" +
            "  </B>" +
            "</A>";
    XmlMapper mapper = new XmlMapper();

    A result = mapper.readValue(xml, A.class);

    assertNotNull(result);
}

@Setter
static class A {
    private String c;
    private String e;
    @JsonProperty("B")
    @JacksonXmlElementWrapper(useWrapping = false)
    private List<B> bs;
}

@Setter
static class B {
    private String d;
    private String f;
}

}`

Exception:

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of NilTest$B (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('ff')
at [Source: (StringReader); line: 1, column: 205] (through reference chain: NilTest$A["B"]->java.util.ArrayList[2])

@cowtowncoder
Copy link
Member

I think this is due to there being no special handling for nsi:nil -- XML specification does not put any special meaning to it (XML Schema specification does).

So to support this, XML format module would need to explicitly understand concept.
It would have to be determined from attribute value to essentially generate JsonToken.VALUE_NULL, instead of whatever contents there might be (ideally I assume element should not contain anything).

I think the first open issue that covers this, then, is #89. There isn't anything special about List/collection values.

@cowtowncoder
Copy link
Member

Filed #354 to cover this and other related issues.

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

2 participants