'JSON parse error: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null');
Requirement is to consume a webservice and persist in database.
I wrote a stand alone class with Resttemplate and it works.
I used same url and same authentication mechanism + spring boot, war deployed on tomcat then when I hit the endpoint(which calls the webservice to get json output) it throws exception.
There was an unexpected error (type=Bad Request, status=400).
JSON parse error: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null'); nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [Source: java.io.PushbackInputStream@4be06322; line: 1, column: 2]
Can someone please assist.
Thanks.
Solution 1:[1]
As you have already said in a comment, the reason your parser was complaining about a '<' character, was that the webservice returned HTML instead of JSON.
Solution 2:[2]
I've had this error many times, and it turns out that I return HTML instead of JSON (hence the < character error).
To fix it, you need to check if the response is JSON or HTML to avoid parsing errors.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kae Verens |
| Solution 2 | Arnav Thorat |
