Skip to content
New issue

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

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

Already on GitHub? # to your account

Only self-closing tag with 'xsi:nil="true"' can be mapped #293

Closed
djdf-shaolin opened this issue May 22, 2018 · 1 comment
Closed

Only self-closing tag with 'xsi:nil="true"' can be mapped #293

djdf-shaolin opened this issue May 22, 2018 · 1 comment

Comments

@djdf-shaolin
Copy link

Hi everybody.

I'm using jackson 2.9.5 and trying to deserialize following simple xml:

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<friends xsi:nil="true"></friends>
</root>

into java objects:

public class Root {
    private Friend[] friends;

    public Friend[] getFriends() {
        return friends;
    }

    public void setFriends(Friend[] friends) {
        this.friends = friends;
    }
}
public class Friend {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

The actual mapping is here:

public class BugStarter {
    public static void main(String[] args) throws IOException, XMLStreamException, TransformerException {
        String xml = "<root xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
                "\t<friends xsi:nil=\"true\"></friends>\n" +
                "</root>";

        XmlMapper xmlMapper = new XmlMapper();
        xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        Root root = xmlMapper.readValue(xml, Root.class);

        System.out.println(root);
    }
}

I'm gettng exception:

com.fasterxml.jackson.databind.exc.MismatchedInputException:
Unexpected end-of-input when binding data into temporary.experimental.jacksonbug.Friend
at [Source: (StringReader); line: 3, column: 8] (through reference chain: temporary.experimental.jacksonbug.Root["friends"]->java.lang.Object[][2])

But when I'm trying to do so with almost same xml, except the tag 'friends' is self-closing, everything works fine

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<friends xsi:nil="true"/>
</root>

I've searched for mapper configuration to avoid this problem and also browsed for xml spec, but seems nothing wrong in both xmls, so I assumed that I've faced mapper issue.

Thanks a lot!

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

No branches or pull requests

2 participants