测试接口,发起请求时候报错JSON parse error: Cannot deserialize instance of java.util.ArrayList<java.lang.Object>

问题一:

JSON parse error: Cannot deserialize instance of java.util.ArrayList<java.lang.Object> out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of java.util.ArrayList<java.lang.Object> out of START_OBJECT token
at [Source: (PushbackInputStream); line: 1, column: 1]

原因:

参数字段不匹配,比如我这里写的后端接口接受的参数是数组(@RequestBody List< String> customers),但是传参又是一个json数据,没对应好(如下图

在这里插入图片描述

解决方法:

数组应该这样子传

在这里插入图片描述

问题二:

Content type ‘text/plain;charset=UTF-8’ not supported

测试接口时,postman:

在这里插入图片描述

后端:

在这里插入图片描述

只需要在请求的请求头上设置Content-Type为application/json就行

在这里插入图片描述

问题三:

The error may involve defaultParameterMap
The error occurred while setting parameters
Cause: java.sql.SQLSyntaxErrorException: Duplicate column name ‘id’; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: Duplicate column name ‘id’

在这里插入图片描述

原因:

连接了多个表都带有id,而我又为了省事直接select *,

解决方法:

要哪些数据就拿那些数据,而我只需要某一张表的字段加上其他表的几个字段就可以用select 表名.星,表名.字段获取

  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,出现这个错误是因为在反序列化过程中,将一个对象值(`JsonToken.START_OBJECT`)转换为类型为`java.util.ArrayList<java.lang.String>`的`ArrayList`时发生了类型不匹配的异常。 解决这个问题的方法是确保要反序列化的JSON数据与目标类型匹配。可以检查JSON数据的结构,确保它是一个数组而不是一个对象。如果JSON数据是一个对象,可以尝试将其转换为数组或使用其他适当的数据结构来存储数据。 以下是一个示例代码,演示了如何解决这个问题: ```java import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.exc.MismatchedInputException; public class JsonDeserializationExample { public static void main(String[] args) { String json = "{\"name\": \"John\", \"age\": 30}"; try { ObjectMapper objectMapper = new ObjectMapper(); ArrayList<String> list = objectMapper.readValue(json, ArrayList.class); System.out.println(list); } catch (MismatchedInputException e) { System.out.println("Cannot deserialize value of type `java.util.ArrayList<java.lang.String>` from Object value (token `JsonToken.START_OBJECT`)"); } catch (Exception e) { e.printStackTrace(); } } } ``` 在这个示例中,我们使用`ObjectMapper`类从JSON字符串中反序列化一个`ArrayList`对象。如果JSON数据不是一个数组,而是一个对象,就会抛出`MismatchedInputException`异常,并打印出相应的错误信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值