Karl Morrison Karl Morrison - 6 months ago 86
Java Question

Faster XML Jackson: Remove double quotes

I have the following json:


I use the following code from Faster XML Jackson.

JsonParser jp = factory.createParser("{\"test\":\"example\"}");
json = mapper.readTree(jp);

It outputs:


Is there a setting in Jackson to remove the double quotes?

fge fge

Well, what you obtain when you .get("test") is a JsonNode and it happens to be a TextNode; when you .toString() it, it will return the string representation of that TextNode, which is why you obtain that result.

What you want is to:


which will return the actual content of the JSON String itself (with everything unescaped and so on).

Note that this will return null if the JsonNode is not a TextNode.