(一)現象
我們在進行服務間的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序列化