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

Support retaining of XML attribute-ness with JsonNode #614

Open
DenisDolgalev opened this issue Oct 8, 2023 · 2 comments
Open

Support retaining of XML attribute-ness with JsonNode #614

DenisDolgalev opened this issue Oct 8, 2023 · 2 comments

Comments

@DenisDolgalev
Copy link

DenisDolgalev commented Oct 8, 2023

Hi!
I've faced an issue working with XML documents (deserialization, modifying, serialization): from JsonNode I can't serialize XML with attributes. Attributes become regular JsonNode fields after deserialization and then serialized as child tags.
Kindly asking to consider adding new Feature (both for deserialization and serialization, disabled by default) to mark attribute field names with special prefix symbol (for example ampersand or underscore if ampersand may break something) during deserialization and, if new Feature enabled, serialize fields with this prefix to XML as attributes of parent tag (removing prefix before serialization), not as child tags.

@cowtowncoder
Copy link
Member

I think that ability to "decorate" attribute names at streaming level -- and not just for JsonNode -- would probably be useful thing. I probably won't have time to do work on this right now, but could help someone if they wanted to.

Support, if any, should probably be enabled/disabled with 2 new features: one for reading (FromXmlParser.Feature) and another for writing (ToXmlGenerator.Feature).

I guess this should work something like:

  1. When reading, attribute names would be mutated to have leading @, exposed for JsonToken.FIELD_NAME
  2. When writing, if (and only if) JsonToken.FIELD_NAME being written has @ prefix, that'd be stripped and value output as attribute.

I suspect there would be some challenges due to use of incremental generator: all attributes need to be written before any elements. So not 100% sure it would actually work as expected.

But reader side seems simple enough.

@alturkovic
Copy link

I am also very interested in this feature. +1

Also, if there is a property with multiple attributes and a text, it would be great to group them together and put a new key for the actual text of the property. I think this tool does a great job at converting XML to JSON while preserving attribute/text when necessary.

@cowtowncoder cowtowncoder changed the title XML attributes processing Support retaining of XML attribute-ness with JsonNode Feb 2, 2024
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

3 participants