Fix Java.lang.IllegalArgumentException:No converter found for return value of Type:class java.util.ArrayList this issue

Source: Internet
Author: User

Today, using the SSM framework, with @responsebody annotations, this problem arises.

Java.lang.IllegalArgumentException:No Converter found for returnValue of type:classJava.util.ArrayList at Org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters (Abstractmessageconvertermethodprocessor.java:187) at Org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue ( Requestresponsebodymethodprocessor.java:174) at Org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue ( Handlermethodreturnvaluehandlercomposite.java:81) at Org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle ( Servletinvocablehandlermethod.java:132) at Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod ( Requestmappinghandleradapter.java:827) at Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal ( Requestmappinghandleradapter.java:738) at Org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle ( Abstracthandlermethodadapter.java:85) at Org.springframework.web.servlet.DispatcherServlet.doDispatch (Dispatcherservlet.java:963) at Org.springframework.web.servlet.DispatcherServlet.doService (Dispatcherservlet.java:897) at Org.springframework.web.servlet.FrameworkServlet.processRequest (Frameworkservlet.java:970) at Org.springframework.web.servlet.FrameworkServlet.doPost (Frameworkservlet.java:872) at Javax.servlet.http.HttpServlet.service (Httpservlet.java:661) at Org.springframework.web.servlet.FrameworkServlet.service (Frameworkservlet.java:846) at Javax.servlet.http.HttpServlet.service (Httpservlet.java:742) at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (Applicationfilterchain.java:231) at Org.apache.catalina.core.ApplicationFilterChain.doFilter (Applicationfilterchain.java:166) at Org.apache.tomcat.websocket.server.WsFilter.doFilter (Wsfilter.java:52) at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (Applicationfilterchain.java:193) at Org.apache.catalina.core.ApplicationFilterChain.doFilter (Applicationfilterchain.java:166) at Org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal (Characterencodingfilter.java: 197) at Org.springframework.web.filter.OncePerRequestFilter.doFilter (Onceperrequestfilter.java:107) at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (Applicationfilterchain.java:193) at Org.apache.catalina.core.ApplicationFilterChain.doFilter (Applicationfilterchain.java:166) at Org.apache.catalina.core.StandardWrapperValve.invoke (Standardwrappervalve.java:198) at Org.apache.catalina.core.StandardContextValve.invoke (Standardcontextvalve.java:96) at Org.apache.catalina.authenticator.AuthenticatorBase.invoke (Authenticatorbase.java:478) at Org.apache.catalina.core.StandardHostValve.invoke (Standardhostvalve.java:140) at Org.apache.catalina.valves.ErrorReportValve.invoke (Errorreportvalve.java:80) at Org.apache.catalina.valves.AbstractAccessLogValve.invoke (Abstractaccesslogvalve.java:624) at Org.apache.catalina.core.StandardEngineValve.invoke (Standardenginevalve.java:87) at Org.apache.catalina.connector.CoyoteAdapter.service (Coyoteadapter.java:342) at Org.apache.coyote.http11.Http11Processor.service (Http11processor.java:799) at Org.apache.coyote.AbstractProcessorLight.process (Abstractprocessorlight.java:66) at Org.apache.coyote.abstractprotocol$connectionhandler.process (Abstractprotocol.java:861) at Org.apache.tomcat.util.net.nioendpoint$socketprocessor.dorun (Nioendpoint.java:1455) at Org.apache.tomcat.util.net.SocketProcessorBase.run (Socketprocessorbase.java:49) at Java.util.concurrent.ThreadPoolExecutor.runWorker (Threadpoolexecutor.java:1142) at Java.util.concurrent.threadpoolexecutor$worker.run (Threadpoolexecutor.java:617) at Org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run (Taskthread.java:61) at Java.lang.Thread.run (Thread.java:748)

This is because SPRINGMVC default is no object converted to JSON converter, we need to configure other converters, here I used Ali's Fastjson

First introduce the Fastjson jar package

Then configure it in the SPRINGMVC configuration file

 

<!--Configuring note Drivers -    <Mvc:annotation-driven>        <mvc:message-convertersRegister-defaults= "false">            <Beanclass= "Org.springframework.http.converter.StringHttpMessageConverter"/>            <Beanclass= "Org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter"/>            <Beanclass= "Org.springframework.http.converter.ByteArrayHttpMessageConverter"/>            <Beanclass= "Org.springframework.http.converter.BufferedImageHttpMessageConverter"/>            <!--Configuring Fastjson Support -            <BeanID= "Fastjsonhttpmessageconverter"class= "Com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">                < Propertyname= "Supportedmediatypes">                    <List>                        <value>Text/html;charset=utf-8</value>                        <value>Application/json;charset=utf-8</value>                    </List>                </ Property>            </Bean>        </mvc:message-converters>    </Mvc:annotation-driven>

After restarting the server, the problem is resolved after running

Fix Java.lang.IllegalArgumentException:No converter found for return value of Type:class java.util.ArrayList this issue

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.