(一)现象
我们在进行服务间的rpc调用时,可能会遇到org.springframework.http.converter.HttpMessageNotReadableException异常。
其具体报错如下:
{
"timestamp": 1456043810789,
"status": 400,
"error": "Bad Request",
"exception": "org.springframework.http.converter.HttpMessageNotReadableException",
"message": "Could not read JSON: Can not deserialize instance of java.lang.String out of START_OBJECT token\n at [Source: java.io.PushbackInputStream@eaa3acb; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token\n at [Source: java.io.PushbackInputStream@eaa3acb; line: 1, column: 1]",
"path": "/app/loginuser"
}
(二)原因
这主要是因为调用方在以post json方式请求服务时,没有对参数进行json序列化。
若为python项目: 可使用json.dumps()
若为java项目: 可以使用fastJson进行json序列化