1

I am working on the project which uses Spring 4.3.2.Release and hibernate 5.2.9.Final versions. It is a Spring + hibernate + Restful service based example.

While doing the demo I got the error : No Converter found:

Following are the credentials of my code.

servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">

    <mvc:annotation-driven/>
    <mvc:default-servlet-handler/>
    <context:annotation-config/>
    <context:component-scan base-package="practice.ngresource.tryone.controller.**"></context:component-scan>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/views/"></property>
        <property name="suffix" value=".html"></property>
    </bean>

</beans>

This is Rest Controller.

import org.springframework.web.bind.annotation.RestController;

import practice.ngresource.tryone.model.Task;


@RestController
@RequestMapping("/trialone")
public class TrialController {

    @ResponseStatus(HttpStatus.OK)
    @RequestMapping(value="/trial",method=RequestMethod.GET)
    public List<Task> taskList(){
        System.out.println("inside the gettasklist");
        List<Task> list = new ArrayList<>();
        list.add(new Task("one","oneDesc","completed"));
        list.add(new Task("Two","twoDesc","completed"));
        list.add(new Task("Three","threeDesc","pending"));
        list.add(new Task("four","fourDesc","pending"));
        list.add(new Task("five","fiveDesc","completed"));
        return list;
    }

}

View and correspond JS page is :

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body ng-app="trial1App" ng-controller="trialController as tCont">
        <h1>The Task List is as follow</h1>
        <div>
            <table>
                <tr ng-repeat="data in tCont.tasks">
                    <td>{{data.taskName}}</td>
                </tr>
            </table>

        </div>

        <script type="text/javascript"
        src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>
        <script type="text/javascript"
        src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular-resource.min.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
        <script>



            var trialApp = angular.module('trial1App', ['ngResource']);

            trialApp.factory('Task',['$resource',function($resource){
                    return $resource('http://localhost:8080/NgRes_Prac_001/trialone/trial/:trialId',
                            {trialId:'@tId'},
                            {
                                updateTask : {method : 'PUT'}
                            });
                }]);

            trialApp.controller('trialController', ['$scope','Task',function($scope,Task){
                    var ob = this;
                    ob.tasks = [];
                    ob.fetchAllTasks = function(){
                            console.log("Inside Fetch all list");                           
                            ob.tasks = Task.query();
                            console.log("Fetch List Completed");
                        };

                    ob.fetchAllTasks();
                }]);



        </script>
</body>
</html>

And following is my error status.

Apr 17, 2017 1:43:24 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [ngRs001] in context with path [/NgRes_Prac_001] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList] with root cause
java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList
    at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:188)
    at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:173)
    at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:81)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:130)
    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.doGet(FrameworkServlet.java:861)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

Please help me through this. Thanks in advance.

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
Vijay Karchi
  • 13
  • 1
  • 5

2 Answers2

0

Typically whenever you see an error dealing with conversion (like yours) it is caused by incompatible data types.

A quick look at the error message makes it look like

List<Task> list = new ArrayList<>();

is the culprit. list and ArrayList seem to be incompatible types. This could mean type-casting is necessary or maybe you should look into making 'list' a different type.

--Edit-- One other possibility is missing dependencies. Make sure everything is being referenced properly inside the project.

Hope this is at least somewhat useful,
-Joseph

Joseph Meadows
  • 160
  • 2
  • 8
0

If you have @RestController on your controller that should be enough in order to convert your data to JSON String, however, I looked it up and it seems that you're missing getters\setters in your Task Class.

according to:

How to return JSON data from spring Controller using @ResponseBody

and:

java.lang.IllegalArgumentException: No converter found for return value of type

Community
  • 1
  • 1
Moshe Arad
  • 3,587
  • 4
  • 18
  • 33