jackson-dataformat-xml icon indicating copy to clipboard operation
jackson-dataformat-xml copied to clipboard

Do not try to map attributes from the http://www.w3.org/2001/XMLSchema-instance namespace

Open ewirch opened this issue 5 years ago • 4 comments

Attributes from the http://www.w3.org/2001/XMLSchema-instance namespace are meant to be consumed by the XML parser. XML containing schema references is currently unparsable by Jackson:

class Test {
    public static void main(String[] args) throws IOException {
        var mapper = new XmlMapper();

        mapper.readValue(
            "<dto xmlns=\"http://SomeNamespace\""
                + "   xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
                + "   xsi:schemaLocation=\"http://SomeNamespace"
                + "                       http://SomeNamespace/schema.xsd\" >"
                + " <value>hello</value>"
                + "</dto>",
            Dto.class
        );
    }

    static class Dto {
        public String value;
    }
}

Fails with

Exception in thread "main" com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "schemaLocation" (class com.smarthost.api.components.offers.email.Test$Dto), not marked as ignorable (one known property: "value"])

ewirch avatar Aug 22 '19 08:08 ewirch

That might make sense as an improvement, even though core XML specification actually says nothing about this namespace (since it was added later on in XML Schema), and XML Schema being an optional part of XML processing. But since these attributes are widely used, yes, it would probably make sense to gracefully ignore them.

Question is just... are there are any cases where user might want to bind them? Or can they be just dropped. There is another issue to make use of xsi:nil attribute, so this could be handled as part of that issue.

cowtowncoder avatar Aug 22 '19 17:08 cowtowncoder

Note: reading of xsi:nil implemented (#354), writing planned to be added (optional), #360.

cowtowncoder avatar Sep 08 '19 21:09 cowtowncoder

I assume https://github.com/FasterXML/jackson-dataformat-xml/issues/354#issuecomment-566041199 is related to this?

henrik242 avatar Dec 16 '19 12:12 henrik242

@henrik242 possibly.

cowtowncoder avatar Dec 17 '19 00:12 cowtowncoder