On Tue, Jul 26, 2022 at 11:58 AM Norbert Kiesel <
nki...@gmail.com> wrote:
>
> tldr: Thanks so much for opening my eyes! Problem solved!
>
> Longer version: my mistake was that I assumed I must add an explicit namespace to every mapped field. Your "it is a fundamental property" made me think: can't I just drop the explicit namespace annotations? And the answer is: yes.
>
> I had XML like <?xml version="1.0" encoding="UTF-8"?><mdf:flow xmlns:mdf="
http://www.foo.com/mdf"><mdf:code>code123</mdf:code><mdf:name>myName</mdf:name></mdf:flow> and I thought I had to explicitly add @JacksonXmlProperty(namespace = "
http://www.foo.com/mdf") to every pojo field. But as it turns out, parsing this XML works w/o any annotations!
Ah. Ok, yes, I was overcomplicating the problem in my head. Now your
question makes perfect sense.
Thank you for explaining things; I jumped to wrong conclusions early
(based on other challenges with namespaces).
What you found out is true, of course, but one caveat: if you need to
write XML, you do need those namespace declarations for
interoperability.
The fact that Jackson XML module accepts content using just the local
name can be seen both as a feature and a bug. :)
(meaning: some users would prefer strict matching to catch potentially
incorrect XML)
-+ Tatu +-
ps. There probably is another feature request in here: it would be
"Default XML namespace for Java types" instead of "Default XML
namespace within XML document". I'll keep that in mind for the future.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/jackson-user/d556c376-5d56-43d4-9d09-37c1d6580038n%40googlegroups.com.