Json转换错误:No converter found for return value of type解决办法

2022-11-29 16:08:56 浏览数 (1)

调试一个maven构建的SSM项目,后端到前端转换成json报如下错:

代码语言:javascript复制
exception org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException

解决办法:网上大佬说是json转换错误,所以需要添加依赖,再配置一下springmvc配置文件再重启服务器即可!

pom.xml添加依赖:

代码语言:javascript复制
  <properties>
    <jackson.version>2.5.4</jackson.version>
  </properties> 

  <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
      <version>${jackson.version}</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>${jackson.version}</version>
    </dependency>

springmvc配置文件添加如下配置:

代码语言:javascript复制
<mvc:annotation-driven>
     <mvc:message-converters>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
   </mvc:message-converters>
</mvc:annotation-driven>

重启项目,测试:

0 人点赞