When sending JSON requests to the server, I'm often greeted by this message:
The request sent by the client was syntactically incorrect ().
Usually it's an incorrect attribute that was passed that the controller didn't expect, since the object the JSON maps to doesn't contain it.
Finding the parameter is needlessly time consuming - is there a way to get more information, perhaps even a stack trace of the exception? I've tried running in debug mode and I'm using Jackson as my JSON (de)serialiser.
To get more info / stack trace turn on debug logging for spring web in log4j.properties
log4j.logger.org.springframework.web=debug
If the data that your consuming is from an external api and if you want to shield your controller from unnecessary elements/properties that you dont need you can use below annotation on POJO class
@JsonIgnoreProperties(ignoreUnknown = true)
or you could set it globally
//jackson 2.0
jsonObjectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Old case, my be irrelevant by now, but for others with similar trouble I'll add this entry.
Check that you have double quotes, not single quotes. Also try escaping them.
I used the app curl for my test json requests.
My JSON was like this
{ 'name' : 'somedata', 'town':'some town' }
and it just blew up in my eyes.
"The request sent by the client was syntactically incorrect" was the general error. So I changed it from single quotes to double quotes, no go. I then tried having a backslash infront of the single quotes, still no go. Then changed it to backslash infront of the double quotes and presto!
curl -i -H "Accept: application/json" -H "Content-Type: application/json" \
http://localhost:8077/dra/dump.json \
-X PUT -d "{\"name\" : \"My Name\", \"town\":\"My Town\"}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With