Home » Java » No converter found for return value of type: class java.util.ArrayList (Spring Boot)

No converter found for return value of type: class java.util.ArrayList (Spring Boot)

Posted by: admin July 15, 2018 Leave a comment

Questions:

I am new to Spring Boot and working on database connectivity. All the related classes are here only main class having run method is not posted.

It is giving me the error of no converter found for ArrayList.

Please help me if I am doing anything wrong.

//Customer.java

package springbootfirstapp.domain;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Customer {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="id")
private int id;

private String name;
private String phone;

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}
public String getPhone() {
return phone;
}

public void setPhone(String phone) {
    this.phone = phone;
}

public Customer(int id, String name, String phone) {
    super();
    this.id = id;
    this.name = name;
    this.phone = phone;
}

public Customer() {
    super();
}
}

//CustomerController.java

package springbootfirstapp.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import springbootfirstapp.domain.Customer;
import springbootfirstapp.repo.CustomerRepo;

@RestController
@RequestMapping("/customer")
public class CustomerController {

@Autowired
CustomerRepo rp;

@RequestMapping("/findall")
@ResponseBody
public List<Customer> findall()
{
    return rp.findAll();
}
}

//CustomerRepo.java

package springbootfirstapp.repo;
import org.springframework.data.jpa.repository.JpaRepository;
import springbootfirstapp.domain.Customer;
public interface CustomerRepo extends JpaRepository<Customer, Integer> {
}

//pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>SpringBootFirstApp</groupId>
<artifactId>springbootfirstapp</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.5.RELEASE</version>
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEndoing>UTF-  8</project.reporting.outputEndoing>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>

</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
</project>

STACKTRACE:

enter image description here

Answers: