{"code":500,"msg":"Invalid JSON input: Cannot construct instance of `com.qianya.dto.api.ApiQueuesAddParm` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('{\"inspectionNo\": \"77690\", \"name\": \"姭荚\", \"sex\": 0, \"age\": 50, \"type\": 4, \"checkItem\": 0, \"isAddProject\": 0, \"departmentsDataList\": [{\"departmentsId\": 2, \"departmentsProjectNumber\": \"1,2,3\", \"isBeforeDinner\": 0}, {\"departmentsId\": 1, \"departmentsProjectNumber\": \"4,5,6\", \"isBeforeDinner\": 0}, {\"departmentsId\": 3, \"departmentsProjectNumber\": \"7,8,9\", \"isBeforeDinner\": 0}]}'); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `com.qianya.dto.api.ApiQueuesAddParm` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('{\"inspectionNo\": \"77690\", \"name\": \"姭荚\", \"sex\": 0, \"age\": 50, \"type\": 4, \"checkItem\": 0, \"isAddProject\": 0, \"departmentsDataList\": [{\"departmentsId\": 2, \"departmentsProjectNumber\": \"1,2,3\", \"isBeforeDinner\": 0}, {\"departmentsId\": 1, \"departmentsProjectNumber\": \"4,5,6\", \"isBeforeDinner\": 0}, {\"departmentsId\": 3, \"departmentsProjectNumber\": \"7,8,9\", \"isBeforeDinner\": 0}]}')\n at [Source: (PushbackInputStream); line: 1, column: 1]","data":null}
时间: 2023-07-06 19:35:41 浏览: 87
Node.js:开启全栈开发的钥匙.pdf
根据错误信息来看,是传入的JSON字符串无法转换为指定的Java对象,具体原因是缺少一个接收字符串参数的构造方法,导致反序列化失败。
解决方法可以有两种:
1. 在Java对象中添加一个接收字符串参数的构造方法,用于反序列化时将JSON字符串转换为Java对象。例如:
```java
public ApiQueuesAddParm(String json) {
ObjectMapper mapper = new ObjectMapper();
try {
ApiQueuesAddParm obj = mapper.readValue(json, ApiQueuesAddParm.class);
this.inspectionNo = obj.getInspectionNo();
this.name = obj.getName();
// 其他字段类似
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
```
2. 在反序列化时,使用ObjectMapper的readValue方法,将JSON字符串转换为Java对象。例如:
```java
ObjectMapper objectMapper = new ObjectMapper();
ApiQueuesAddParm param = objectMapper.readValue(jsonData, ApiQueuesAddParm.class);
```
其中,jsonData是传入的JSON字符串,ApiQueuesAddParm.class是要转换的Java对象的类型。这种方法不需要在Java对象中添加额外的构造方法,但需要使用ObjectMapper对象进行反序列化。
阅读全文