The problem : Deserializing a JSON String with escape characters in Java & Gson/Jackson adds additional escaping characters when deserializing JSON.
Desired Results : Return the exact JSON value when deserialized to text without any additional escaping values using either Gson or Jackson?
Desired return value: //Brindle
ie. testFile.json
{
"dogs" : {
"Boxer" : "//Brindle",
"Lab: "//Golden"
}
}
Non Desired Returned Results : "\/\/Brindle"
Things I’ve tried which haven’t succedded
- Adding custom Gson Adapter to deserialize the fields as
getAsString()
- Using Jackson ObjectMapper to convert back and forth to show idempotence
- Iterating JSON Object and manually enforcing the String with
addProperty()
- using Gson Annotation bindings to set desired mapping
- Set Gson (GsonBuilder) to
disablehtmlescaping()
The following conversions can happen and all of which return a deserialized String with additional escaping characters.
- File -> JSON -> POJO -> String
- JSON -> String
- String -> POJO -> JSON -> String
Ultimate questions : How do you have Java return a String with additional escaped characters when