Thank you for the prompt response Tatu :)
I was wondering if I had incorrectly configured Jackson or the XML parser. 
So your confirmation is much appreciated.

Luki

On Sunday, June 27, 2021 at 9:02:38 PM UTC+1 Tatu Saloranta wrote:

> On Sun, Jun 27, 2021 at 9:33 AM Luki de Silva <[email protected]> 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/4259470d-ff5b-4359-8671-915d5d8fc06an%40googlegroups.com.

Reply via email to