JSON parse error: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null');
Asked Answered
W

2

9

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.

Windowlight answered 25/1, 2018 at 14:38 Comment(5)
I got this exception in different context, when I write a standalone program with RestTemplate to call webservice I get proper json format output. Same code snippet I call from a RestController it throws exception.Windowlight
Looks like the data you are submitting isn't formatted properly. You should post the code that you are using to make the call.Chilt
issue resolved now, it is because weird behavior or webservice. I have created a standalone program with Resttemplate to consume webservice and it works fine and I get object array(json converted to java object). but when I bundle my code in war and deploy in server and access rest end point, that time I got html response instead of json. hence it was throwing jsone parse exception. thank you.Windowlight
in wht format you want to parse dataGiuseppinagiustina
it could also be caused by accientally trying to parse an xml file using ObjectMapperCatt
S
1

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.

Spire answered 10/4, 2022 at 18:46 Comment(1)
Actually, you need to find out why you receive html and fix it he reason in your code, if possible. Most common reasons: You asked for html, you didn’t ask for JSON, or some stupid captive network inserted it’s own things into an http (not https) resource.Banksia
N
0

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.

Newspaperwoman answered 10/4, 2022 at 16:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.