$.ajax函数调接口,报异常No converter found for return value of type: class java.util.ArrayList

时间:2021-07-12 21:16:41

接口正常执行,返回给前端后报服务器500异常,异常详情:

org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type: class java.util.ArrayList

 

原因没有深究,大概是$.ajax函数在前端接收的数据类型为JSON,而服务中没有能将ArrayList转换成JSON的类。

暂时记下解决方案——在项目中添加JSON全家桶的依赖如下:

<dependency>
<groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.9.9</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.9.9</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.9.9</version> </dependency>