:Failed
to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException:
JSON parse error: Cannot construct instance of `com.example.demo.model.Customer`
(although at least one Creator exists): no String-argument constructor/factory
method to deserialize from String value
('{"id":0,"name":"abc","city":"def","contactNum":334455}');
在spring boot前端访问接口突然出现上述错误,后台接收参数接收到了字符串,导致不能反序列化。但是前端代码看不出任何问题。
解决办法:增加一个构造函数来手动赋值
public SubmitParam(String json) throws IOException{ SubmitParam param = new ObjectMapper().readValue(json, SubmitParam.class); this.id=param.getId(); this.phoneResult = param.getPhoneResult(); this.remark = param.getRemark(); this.isContinue = param.getIsContinue(); this.nextFollowUpTime = param.getNextFollowUpTime(); }
小记录一下。