Error: HttpMessageNotReadableException: JSON parse error: Unrecognized token 'id': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')]

Cause: Used curl command to test serializing JSON object into java script class using @JSONCreator decorator. This triggered crash when converter hits the 2nd nested JSON object given in the curl command. Notice the terminal output information is not important; instead, the pattern is important. The pattern repeats "...URL function" 2x times. Then repeats "...between 0 and 65535" 3x times. This error message pattern will change depending on the number of input JSON key-value pairs given for either JSON object.

Possible Reason for crash: It appears the error might be rooted in the TOKEN parser repeating the for-loop search of key-value pairs based on the '{' bracket TOKEN. However, the for-loop search for key-value pairs erroneously loops through the original key-value pairs while trying to for-loop the 2nd nested JSON object, instead of just for-looping the new JSON nested object.

Curl command used => curl -X POST -H 'Content-Type: application/json' -d '{"Host":"test","Port":"667","Path":"/it","Data":'{"id":"mouse","role":"employee","year":"1984"}'}' http://localhost:8080/users

Terminal Output:

curl: (3) URL rejected: Malformed input to a URL function curl: (3) URL rejected: Port number was not a decimal number between 0 and 65535 curl: (3) URL rejected: Port number was not a decimal number between 0 and 65535 curl: (3) URL rejected: Port number was not a decimal number between 0 and 65535 curl: (3) URL rejected: Malformed input to a URL function curl: (3) URL rejected: Port number was not a decimal number between 0 and 65535 curl: (3) URL rejected: Port number was not a decimal number between 0 and 65535 curl: (3) URL rejected: Port number was not a decimal number between 0 and 65535

Ben

Comment From: sbrannen

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.


In any case, this does not appear to be an issue with Spring.

Rather, it looks like you are using the wrong syntax for the curl command.

You likely cannot nest a single quote (') within enclosing single quotes in your shell.