jackson-dataformat-xml
jackson-dataformat-xml copied to clipboard
Do not try to map attributes from the http://www.w3.org/2001/XMLSchema-instance namespace
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"])
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.
Note: reading of xsi:nil
implemented (#354), writing planned to be added (optional), #360.
I assume https://github.com/FasterXML/jackson-dataformat-xml/issues/354#issuecomment-566041199 is related to this?
@henrik242 possibly.