Replies: 1 comment 2 replies
-
My suggestion would be read content as |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am looking for the proper way to strip unicode null (
\u0000
) characters fromTextNode
objects, within theObjectNode
(extendingJsonNode
).Firstly, a JSON String containing
\\u0000
(double backslash is intentional here) is converted into aJsonNode
. The result object contains aLinkedHashMap
with an element with a key of type String and a value of typeTextNode
. TheTextNode
unescapes the String and it actually contains a single unicode null character.Secondly, the resulting object can become a property of another object or an element of a collection. Then this "another object" or a collection is serialized using
valueToTree
. Here, for simplicity, I am skipping this "wrapping" part and it's just callingvalueToTree
over theJsonNode
:What I am trying to achieve is to strip the unicode null characters when calling the
valueToTree
over the 2nd object.I could not find any way to apply a
JsonSerializer
to work with theTextNode
objects.I was able to do that by overriding the mapper's
JsonNodeFactory
:What I don't like with this approach is the assumption on what the original node factory object is and its defaults.
For the context, these are another settings that I use with the mapper object:
I am not stripping the character in the first step (
readTree
) as this actually can come from multiple sources and filtering it in a single place seems more reasonable.Version information
Which Jackson version(s) was this for? 2.14.2
JDK - Temurin-11.0.15+10
Beta Was this translation helpful? Give feedback.
All reactions