Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unbound namespace URI '' when using isAttribute=true on JacksonXmlProperty #311

Closed
fredrik-rambris opened this issue Sep 27, 2018 · 4 comments

Comments

@fredrik-rambris
Copy link

When streaming beans and producing XML I get an exception saying Unbound namespace URI '' when I am using @JacksonXmlProperty(isAttribute=true).

@JacksonXmlProperty(isAttribute = true)
private String source="ECOM";
private Member member;

Using Jackson 2.9.7 with woodstox 5.0.3.

If I set
xmlOutputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true);
The code works but then the produced document has no xmlns.

A gist displaying the failing code

@cowtowncoder
Copy link
Member

Interesting. You are right, there is an exception, and unexpected one at that.
I would have thought that works fine, and it should I think. I'll see if I can figure out what causes it, fix.

@cowtowncoder
Copy link
Member

Also interesting: fails on 2.x, but passes on 3.0.0-SNAPSHOT for some reason. Hmmh.

@cowtowncoder
Copy link
Member

cowtowncoder commented Dec 16, 2018

Oh, actually... so, exception is weird, but one thing to note is that you MUST NOT turn off namespace repairing. Jackson XML module absolutely expects and requires it be enabled; I'll probably add a check so that attempting to use one without will fail when constructing XmlMapper. I can't think of valid reasons for needing to disable it, but I think you are attempting to use it as workaround for a problem.

I also wonder if you might be misunderstanding how XML namespaces, and in particular default namespace works with attributes: it is different from elements. That is, "default namespace" only ever applies to elements, and never to attributes: attribute without prefix always has namespace of "". To have attribute in a different namespace requires use of namespace bound to explicit prefix.
So it may make sense for you to read XML namespace specification (or an article that explains it) -- there are some subtleties there which are not necessarily intuitive, such as above-mentioned difference between attributes and elements wrt default namespace binding.

@cowtowncoder
Copy link
Member

Filed #326 as replacement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants