解决JSON parse error: Cannot construct instance of...问题

最新修改了一个接口,在DTO类中新增了instanceConnectInfo字段(类型为JSONObject),结果和前端联调的时候就出现了这个问题

JSON parse error: Cannot construct instance of com.alibaba.fastjson.JSONObject (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value (’’); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of com.alibaba.fastjson.JSONObject (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value (’’)↵ at [Source: (PushbackInputStream); line: 1, column: 520] (through reference chain: cn.ccsiot.biz.modelmachine.modelmachineinfo.model.AddOrEditModelMachineForm[“instanceConnectInfo”])

排查:
 no String-argument constructor/factory method to deserialize from String value (’’);
看到这里我就怀疑前端传参的时候instanceConnectInfo给我传了空串,于是去前端那边看了参数,果不其然instanceConnectInfo参数给了个空串。

解决:
 和前端沟通,参数为空时默认给我传一对大括号{}(对象),再次测试,问题已不存在

你可能感兴趣的:(JSONObject,java)