Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.lang.Integer` from Object value (token `JsonToken.START_OBJECT`); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `java.lang.Integer` from Object value (token `JsonToken.START_OBJECT`)<EOL> at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 1, column: 1]]
时间: 2023-06-26 07:06:09 浏览: 125
这个错误通常是由于请求的 JSON 数据与后台接口定义的数据类型不匹配导致的。在请求中,可能将一个对象传递给了后台接口,但是接口定义的参数类型是 Integer 类型,因此无法将对象转换为 Integer 类型。
你可以检查一下请求发送的数据,确保它符合接口定义的数据类型。如果问题仍然存在,你可以尝试使用 Jackson 的 @JsonView 注解来过滤掉不需要的属性,或者使用 @JsonIgnoreProperties(ignoreUnknown = true) 来忽略未知属性。如果这些方法都无法解决问题,那么可能需要检查一下接口定义和请求之间的数据类型是否匹配,或者检查一下 JSON 数据格式是否正确。
相关问题
Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot construct instance of
Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error Cannot construct instance of "com.example.User" (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('John Doe'); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of "com.example.User" (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('John Doe')
Resolved exception caused by handler execution: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token at [Source: (PushbackInputStream); line: 1, column: 1]
这个错误是由于前端传递的JSON格式不正确导致的。JSON中的"menus"字段是一个数组,应该以"["开始,以"]"结束,每个菜品信息对象应该以"{"开始,以"}"结束,而前端传递的JSON对象中,"menus"字段后面紧跟着一个大括号"{", 这使得Jackson在反序列化时无法将它转换为List<Menu>对象,因此报错。
你可以将前端传递的JSON对象修改为以下格式,即将"menus"字段的值用"["和"]"包裹起来,同时将每个菜品信息对象用"{"和"}"包裹起来:
```
{
"menus": [
{
"name": "红烧土豆",
"price": 10.11
},
{
"name": "清蒸鲫鱼",
"price": 25.11
}
]
}
```
这样就可以成功地将JSON对象转换为List<Menu>对象了。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)