I'm trying to use org.apache.httpcomponents
to consume a Rest API, which will post JSON format data to API.
I get this exception:
Caused by: com.fasterxml.jackson.core.JsonParseException: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string.
The reason is because ctrl-char
is included in the JSON string.
Is there any way to replace this or some other solution?
This can happen if you have a newline (or other control character) in a JSON string literal.
{"foo": "bar
baz"}
If you are the one producing the data, replace actual newlines with escaped ones "\\n"
when creating your string literals.
{"foo": "bar\nbaz"}