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

Add a feature to support writing xsi:nil attribute for null values #360

Closed
cowtowncoder opened this issue Sep 8, 2019 · 2 comments
Closed
Milestone

Comments

@cowtowncoder
Copy link
Member

cowtowncoder commented Sep 8, 2019

(note: follow-up for #354

Now that Jackson processes xsi:nil on reader side, with 2.10, it would make sense to also emit those declarations in some cases. Since this is additional content (attribute) that some other systems might not recognize (or users not want), this should be added as ToXmlGenerator.Feature, defaulting to false (i.e. do not write xsi:nil).

@Migwel
Copy link
Contributor

Migwel commented Oct 27, 2020

I'd like to give this one a go, @cowtowncoder . Any suggestion on how to tackle this? I see that we have a method com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator#writeNull but I'm not sure (yet) if the change should happen there or also in the xmlWriter itself

@cowtowncoder
Copy link
Member Author

@Migwel I fixed one typo in description: feature to add would be in generator (ToXmlGenerator).

But yes, I think that would be the method to modify. Looking at it, I think first cases -- attribute, "unwrapped" -- probably need to be left as is (i.e. cannot make use), and it's the 3rd case that matters.
In that section, instead of writing empty element, would have to change it to write start element, write namespaced attribute (xsi:nil, with proper namespace passed, so using Stax write method that take local name, prefix and URI all), and then write end element.
Tricky part would be that of indentation, not sure how to support pretty-printing (indenting) case -- probably would (eventually?) need to change XmlPrettyPrinter to allow for this case. But maybe start with simpler part.

One possible complication is that while Stax generator will handle namespace declaration for xsi, it may get unwieldy with multiple declarations. But I guess we'll see, starting with what can be done.

cowtowncoder pushed a commit that referenced this issue Nov 11, 2020
* Part of #360, use xsi:nil for null value with non-pretty writer

* Use proper namespace for xsi:nil attribute
@cowtowncoder cowtowncoder added this to the 2.12.0-rc2 milestone Nov 11, 2020
@cowtowncoder cowtowncoder added 2.12 and removed active labels Nov 11, 2020
cowtowncoder added a commit that referenced this issue Nov 13, 2020
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