On Sun, Jun 27, 2021 at 9:33 AM Luki de Silva <lak...@gmail.com> wrote: > > Hello all, > > I am trying to get Jackson XML deserializer to ensure that XML elements that > have been qualified by a namespace in the target POJO is correctly handled. > > This is my POJO class. > > @XmlRootElement(name = "open", namespace="foo") > public static class OpenStream { > > @XmlAttribute > private String id; > > public OpenStream() {} > } > > As you can see, the root element "open" is qualified by the "foo" namespace. > > And this is the code I am running to deserialize the some XML to this POJO. > > @Test > public void testJAXB_JacksonWoodstox() throws Exception { > XMLInputFactory2 inputFactory = new WstxInputFactory(); > inputFactory.configureForSpeed(); > > XMLOutputFactory2 outputFactory = new WstxOutputFactory(); > outputFactory.configureForSpeed(); > > XmlMapper mapper = new XmlMapper(new XmlFactory(inputFactory, > outputFactory)); > mapper.registerModule(new JaxbAnnotationModule()); > > OpenStream open = mapper.readValue("<open id=\"1\"/>", OpenStream.class); > assertEquals("1", open.id); > } > > The XML string input to mapper does not have the "foo" namespace, and > therefore I expect Jackson to FAIL the operation. However, it happily > deserializes the XML and creates the POJO. > > I tested the identical XML through standard JAXB (coupled with Woodstox) > which throws an exception, as expected, with the following message. > > unexpected element (uri:"", local:"open"). Expected elements are <{foo}open>] > > Am I missing something or is this behaviour not available in Jackson?
You are correct: Jackson does not verify matching of the namespaces currently: it will produce expected namespaces on generation but basically ignore them on reading. -+ Tatu +- -- You received this message because you are subscribed to the Google Groups "jackson-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/CAL4a10g85vOWQzYQa2QkvC7ydCrE7%3DQ41jnZ_-nxHcEG-f%3DOYg%40mail.gmail.com.