I create some JSONObject using java classes. Lets call it MyJSONObject. It should be the inner String part of another JSON object. Like that:
[
{
"httpRequest": {...},
"httpResponse": {
"headers": {
"content-type": [
"application/json"
]
},
"body": "MyJSONObject"
}
]
The problem is when i try to put it as string using mapper.writeValueAsString(MyJSONObject) I receive all the quotes with backslash in console body :
[
{
"httpRequest": {...},
"httpResponse": {
"headers": {...},
"body": "{\"key\":\"value\",\"key\":\"value\"}"
}
]
instead of expected:
"body": "{"key":"value","key":"value"}"
I tried to replace each quote by quote with backslash, using method replace("\"", "\\\"")
to my string, but the result is even worse:
"body": "{\\\"key\\\":\\\"value\\\",\\\"key":\\\"value\\\"}"
How can i just put my string avoid this backslashes?