I want to parse an escaped child json within a parent json. Right now I am using StringEscapeUtils.unescapeJava to first unescape the string. Then I am passing the unescaped string to objectMapper.readTree to get a JsonNode object.
{
"fileName": "ParentJson",
"child": "{\"fileName\":\"ChildJson\",\"Description\":\"Extract string value at child node and convert child json to JsonNode object using only Jackson.\"}"
}
When I use Jackson and read the value of child node, it adds quotes around it. I don't know if this is an expected behavior. So I have to remove those quotes first.
String childString = StringEscapeUtils.unescapeJava(parent.get("child").toString());
childString = StringUtils.removeStart(StringUtils.removeEnd(childString, "\"") , "\"");
JsonNode child = objectMapper.readTree(childString);
I feel like there should be a better way to handle this use case, but I could be wrong.