title: Spring MVC - JSON - Http Status 500: No converter for [class java.util.ArrayList] with preset Content-Type 'null'
body: <p>During learning spring mvc I wanted to display <strong>list of students</strong> from my database in JSON format, but I am still facing the same problem which is:</p>
  <pre><code>HTTP Status 500 – Internal Server Error
  Type Exception Report
  
  Message No converter for [class java.util.ArrayList] with preset Content-Type 'null'
  
  Description The server encountered an unexpected condition that prevented it from fulfilling the request.
  
  Exception
  
  org.springframework.http.converter.HttpMessageNotWritableException: No converter for [class java.util.ArrayList] with preset Content-Type 'null'
      org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:312)
      org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.handleReturnValue(HttpEntityMethodProcessor.java:219)
      org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:78)
      org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:135)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
      org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:655)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
  Note The full stack trace of the root cause is available in the server logs.
  
  </code></pre>
  <p>Here is my full project code:</p>
  <p><strong>Student class</strong></p>
  <pre><code>package com.example.springmvcjpa.model;
  
  import javax.persistence.*;
  
  @Entity
  @Table(name = &quot;student&quot;)
  public class Student {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Integer id;
      private String name;
      private String surname;
  
      public Student(){
  
      }
  
      public Student(Integer id, String name, String surname) {
          this.id = id;
          this.name = name;
          this.surname = surname;
      }
  
      public Integer getId() {
          return id;
      }
  
      public void setId(Integer id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getSurname() {
          return surname;
      }
  
      public void setSurname(String surname) {
          this.surname = surname;
      }
  
      @Override
      public String toString() {
          final StringBuilder sb = new StringBuilder(&quot;Student{&quot;);
          sb.append(&quot;, name='&quot;).append(name).append('\'');
          sb.append(&quot;, surname='&quot;).append(surname).append('\'');
          sb.append('}');
          return sb.toString();
      }
  }
  </code></pre>
  <p><strong>Service class</strong></p>
  <pre><code>package com.example.springmvcjpa;
  
  import com.example.springmvcjpa.model.Student;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  import org.springframework.transaction.annotation.Transactional;
  import java.util.List;
  
  @Service
  @Transactional
  public class StudentService {
  
      StudentRepository studentRepository;
  
      @Autowired
      public StudentService(StudentRepository studentRepository){
          this.studentRepository = studentRepository;
      }
  
      public List&lt;Student&gt; getStudents(){
  
          return studentRepository.findAll();
      }
  }
  </code></pre>
  <p><strong>Repository class</strong></p>
  <pre><code>package com.example.springmvcjpa;
  
  import com.example.springmvcjpa.model.Student;
  import org.springframework.data.jpa.repository.JpaRepository;
  import org.springframework.stereotype.Repository;
  
  @Repository
  public interface StudentRepository extends JpaRepository&lt;Student, Integer&gt; {
  }
  </code></pre>
  <p><strong>Controller class</strong></p>
  <pre><code>package com.example.springmvcjpa.frontcontroller;
  
  
  import com.example.springmvcjpa.StudentService;
  import com.example.springmvcjpa.model.Student;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.http.ResponseEntity;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.RestController;
  import java.util.List;
  
  @RestController
  public class FrontController{
  
      StudentService studentService;
  
      @GetMapping(value = &quot;/welcome&quot;, produces=&quot;application/json&quot;)
      public ResponseEntity&lt;List&lt;Student&gt;&gt; welcomePage(){
  
          List&lt;Student&gt; students = studentService.getStudents();
  
          return ResponseEntity.ok(students);
      }
  
  
      @Autowired
      public FrontController(StudentService studentService){
          this.studentService = studentService;
      }
  
  }
  </code></pre>
  <p><strong>Data Config class</strong></p>
  <pre><code>package com.example.springmvcjpa.configuration;
  
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
  import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  import org.springframework.jdbc.datasource.DriverManagerDataSource;
  import org.springframework.orm.jpa.JpaTransactionManager;
  import org.springframework.orm.jpa.JpaVendorAdapter;
  import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
  import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
  import org.springframework.transaction.PlatformTransactionManager;
  import org.springframework.transaction.annotation.EnableTransactionManagement;
  
  import javax.sql.DataSource;
  import java.util.Properties;
  
  @Configuration
  @EnableTransactionManagement
  @EnableJpaRepositories(basePackages = &quot;com.example.springmvcjpa&quot;)
  @ComponentScan(&quot;com.example.springmvcjpa&quot;)
  public class PersistenceConfig {
  
      @Bean
      public LocalContainerEntityManagerFactoryBean entityManagerFactory(){
          LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
          em.setDataSource(dataSource());
          em.setPackagesToScan(&quot;com.example.springmvcjpa.model&quot;);
  
          JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
          em.setJpaVendorAdapter(vendorAdapter);
          em.setJpaProperties(additionalProperties());
  
          return em;
      }
  
      @Bean
      public DataSource dataSource(){
          DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();
          driverManagerDataSource.setDriverClassName(&quot;com.microsoft.sqlserver.jdbc.SQLServerDriver&quot;);
          driverManagerDataSource.setUrl(&quot;jdbc:sqlserver://LucasPC\\SQLEXPRESS;databaseName=student&quot;);
          driverManagerDataSource.setUsername(&quot;xx&quot;);
          driverManagerDataSource.setPassword(&quot;yy&quot;);
          return driverManagerDataSource;
      }
  
      Properties additionalProperties(){
          Properties properties = new Properties();
          properties.setProperty(&quot;hibernate.hbm2ddl.auto&quot;, &quot;update&quot;);
          properties.setProperty(&quot;hibernate.dialect&quot;,&quot;org.hibernate.dialect.SQLServer2012Dialect&quot;);
          return properties;
      }
  
      @Bean
      public PersistenceExceptionTranslationPostProcessor exceptionTranslator(){
          return new PersistenceExceptionTranslationPostProcessor();
      }
  
      @Bean
      public PlatformTransactionManager transactionManager(){
          JpaTransactionManager transactionManager = new JpaTransactionManager();
          transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
          return transactionManager;
      }
  
  
  }
  </code></pre>
  <p><strong>Web Config class</strong></p>
  <pre><code>package com.example.springmvcjpa.configuration;
  
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.web.servlet.ViewResolver;
  import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  import org.springframework.web.servlet.view.InternalResourceViewResolver;
  
  @Configuration
  @ComponentScan(&quot;com.example.springmvcjpa.frontcontroller&quot;)
  public class MyWebConfig implements WebMvcConfigurer {
  
      @Bean
      public ViewResolver getViewResolver() {
  
          InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver();
          internalResourceViewResolver.setPrefix(&quot;/WEB-INF/views/&quot;);
          internalResourceViewResolver.setSuffix(&quot;.jsp&quot;);
          return internalResourceViewResolver;
  
      }
  
  }
  </code></pre>
  <p><strong>WebInit class</strong></p>
  <pre><code>package com.example.springmvcjpa.configuration;
  
  import org.springframework.web.WebApplicationInitializer;
  import org.springframework.web.context.ContextLoaderListener;
  import org.springframework.web.context.WebApplicationContext;
  import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
  import org.springframework.web.servlet.DispatcherServlet;
  
  import javax.servlet.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.ServletRegistration;
  
  public class MyWebInit implements WebApplicationInitializer {
      @Override
      public void onStartup(ServletContext servletContext) throws ServletException {
          WebApplicationContext context = getWebContext();
          DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
          servletContext.addListener(new ContextLoaderListener(getAppContext()));
  
          ServletRegistration.Dynamic servletRegistration = servletContext.addServlet(&quot;mvc&quot;,dispatcherServlet);
          servletRegistration.setLoadOnStartup(1);
          servletRegistration.addMapping(&quot;/spring-mvc/*&quot;);
  
      }
  
      public AnnotationConfigWebApplicationContext getWebContext(){
          AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
          context.register(MyWebConfig.class);
          return context;
      }
  
      public AnnotationConfigWebApplicationContext getAppContext(){
          AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
          context.register(PersistenceConfig.class);
          context.refresh();
          return context;
      }
  
  
  }
  </code></pre>
  <p><strong>pom.xml</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
           xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
           xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.example&lt;/groupId&gt;
      &lt;artifactId&gt;MvcTest&lt;/artifactId&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;MvcTest&lt;/name&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
          &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.microsoft.sqlserver&lt;/groupId&gt;
              &lt;artifactId&gt;mssql-jdbc&lt;/artifactId&gt;
              &lt;version&gt;9.4.0.jre16&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
              &lt;version&gt;5.6.1.Final&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;javax&lt;/groupId&gt;
              &lt;artifactId&gt;javaee-web-api&lt;/artifactId&gt;
              &lt;version&gt;8.0.1&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
              &lt;artifactId&gt;spring-data-jpa&lt;/artifactId&gt;
              &lt;version&gt;2.6.0&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
              &lt;version&gt;5.3.13&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
              &lt;version&gt;5.3.13&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
              &lt;version&gt;5.3.13&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
              &lt;version&gt;2.13.0&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-core&lt;/artifactId&gt;
              &lt;version&gt;2.13.0&lt;/version&gt;
          &lt;/dependency&gt;
          
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.3.1&lt;/version&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  <p>Structure of project:</p>
  <ul>
  <li>java
  <ul>
  <li>com.example.springmvcjpa
  <ul>
  <li>configuration
  <ul>
  <li>MyWebConfig</li>
  <li>MyWebInit</li>
  <li>PersistenceConfig</li>
  </ul>
  </li>
  <li>frontcontroller
  <ul>
  <li>FrontController</li>
  </ul>
  </li>
  <li>model
  <ul>
  <li>Student</li>
  </ul>
  </li>
  <li>StudentRepository</li>
  <li>StudentService</li>
  </ul>
  </li>
  </ul>
  </li>
  </ul>
  <p>I would be very grateful if someone could help me just  to solve the problem, because at this moment I am not sure if something is wrong with logic in project, or project is missing some Configuration related to JSON or something else.</p>
  <p>Greetings,
  Luke</p>