Replies: 1 comment
-
Quick note: Jackson should not prepend |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have an problem and am not sure how to solve it. I am trying to upgrade our Jackson dependency from 2.12.6 to 2.14.1. I am running into an issue.
The main functionality is to take and XML string and convert it to a JSON string. (Yes, I know this is a hotly debated topic, but it is necessary for our application). I do NOT have any intermediate objects to convert the XML to and then convert it to JSON, as well allow any XML and convert it over to JSON. So, I am going straight from XML to JSON. One of the issues is that Jackson, in version 2.12.6, did not read in attributes that were on the root element in the XML. In order to get around this, we built our own JsonNodeDeserializer by extending com.fasterxml.jackson.databind.deser.std.JsonNodeDeserializer and deserialized the root element attributes into JSON at the top level. As an example:
BTW, We configured the XMLFactory to put '#text' in front of any text strings:
So the JSON would look like:
While doing this, there was some functionality added. Every XML attribute (not part of the root element) had
@
prepended to the name. As an example:would convert to:
It looks like in version 2.14.1 (or some previous version), Jackson started deserializing the XML root element attributes correctly. Thank you for that! This made life a lot easier!
However, I still have the problem of the '@' in front of the attribute name. Is there a way to configure Jackson to change the name of an XML attribute without using annotations on POJOs? OR would I need to create a package "com.fasterxml.jackson.databind.deser.std" in our code base to override the BaseNodeDeserializer to prepend '@' to the attribute name (something I don't want to do)?
Beta Was this translation helpful? Give feedback.
All reactions