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

Make empty tags configurable during serialization #640

Open
wants to merge 6 commits into
base: 2.17
Choose a base branch
from

Conversation

Croway
Copy link

@Croway Croway commented Feb 19, 2024

No description provided.

@@ -559,6 +561,9 @@ private final String _collectUntilTag() throws XMLStreamException
if (FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL.enabledIn(_formatFeatures)) {
return null;
}
if (FromXmlParser.Feature.EMPTY_ELEMENT_AS_EMPTY_ARRAY.enabledIn(_formatFeatures)) {
return JsonToken.START_ARRAY.asString() + JsonToken.END_ARRAY.asString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how this makes sense -- all we get here is String "[]", which won't be further decoded?

@cowtowncoder
Copy link
Member

Ok, I can see what this PR does, but I am not quite sure how it makes any sense as a feature.

@Croway
Copy link
Author

Croway commented Feb 19, 2024

Ok, I can see what this PR does, but I am not quite sure how it makes any sense as a feature.

Hello, I have an usecase (mostly due to compatibility) that requires to have empty xml tags serialized as json empty array.
If you think this usecase does not make sense, could you suggest how to implement it? (custom Serializer?)

@cowtowncoder
Copy link
Member

@Croway I think this is unfortunately bit too specific to add as a general on/off feature.

I suspect it would not be easy to implement as custom deserializer (but might be possible)

I would be open to configuration setting that allows configuring value to return as any String (so in your case, you could set it as "[]"). This would need to be configuration on XmlFactory (through XmlFactoryBuilder -- it has _nameForTextElement to kind of show how to do this I think).
Such general purpose functionality could be useful for other things too I suspect.

@Croway
Copy link
Author

Croway commented Feb 20, 2024

Thanks for the hint @cowtowncoder I have updated the PR.

@Croway Croway changed the title Add EMPTY_ELEMENT_AS_EMPTY_ARRAY Feature Make empty tags configurable during serialization Feb 21, 2024
@cowtowncoder
Copy link
Member

@Croway Ok I think this would work. Before merging, there is one small process part: we'd need CLA from: https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf

this only needs to be done once, before the first contribution and is good all future contributions.

The usual way is to print, fill & sign, scan/photo, email to cla at fasterxml dot com.
And once I get it I can proceed.

Looking forward to merging this new feature!

@pjfanning
Copy link
Member

@Croway Did you ever fill in the CLA? The 2.18.0 RC1 is in a few weeks.

@Croway
Copy link
Author

Croway commented Jul 31, 2024

@Croway Did you ever fill in the CLA? The 2.18.0 RC1 is in a few weeks.

Hi @pjfanning I am truly sorry about this situation, but I am still waiting a response from my company legal team.

@cowtowncoder
Copy link
Member

Quick note: PR would need to be re-based against 2.18 as well.

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

Successfully merging this pull request may close these issues.

3 participants