title: Spring Boot fails to return JSON for a object but not for list of objects
body: <p>I am developing my first Spring Boot application and i ran into a weird problem. The configuration is very basic: </p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.pawsec&lt;/groupId&gt;
      &lt;artifactId&gt;kitchen&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;name&gt;kitchen&lt;/name&gt;
      &lt;description&gt;The Kitchen restaurant system&lt;/description&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.1.0.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-aop&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-jdbc&lt;/artifactId&gt;
          &lt;/dependency&gt; 
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.pawsec&lt;/groupId&gt;
              &lt;artifactId&gt;common&lt;/artifactId&gt;
              &lt;version&gt;1.0&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;executable&gt;true&lt;/executable&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  
  &lt;/project&gt;
  </code></pre>
  
  <p>We have some Javascript code on a page calling these two services. When the controller returns a Guy object in the first method, we get an empty response:</p>
  
  <pre><code>    {data: "", status: 200, statusText: "", headers: {…}, config: {…}, …}
  config: {adapter: ƒ, transformRequest: {…}, transformResponse: {…}, timeout: 0, xsrfCookieName: "XSRF-TOKEN", …}
  data: ""
  headers: {}
  request: XMLHttpRequest {onreadystatechange: ƒ, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …}
  status: 200
  statusText: ""
  : Object
  </code></pre>
  
  <p>When we return a List of Guy objects from the second method, however, we get the full Json structure </p>
  
  <pre><code>back:
  {data: Array(3), status: 200, statusText: "", headers: {…}, config: {…}, …}
  config: {adapter: ƒ, transformRequest: {…}, transformResponse: {…}, timeout: 0, xsrfCookieName: "XSRF-TOKEN", …}
  data: Array(3)
  0: {guyId: 1, name: "Walter Sobchak", age: 45}
  1: {guyId: 2, name: "Jeffrey Lebowski", age: 42}
  2: {guyId: 3, name: "Theodore Donald Kerabatsos", age: 39}
  length: 3
  : Array(0)
  headers: {content-type: "application/json;charset=UTF-8", cache-control: "private", expires: "Thu, 01 Jan 1970 00:00:00 GMT"}
  request: XMLHttpRequest {onreadystatechange: ƒ, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …}
  status: 200
  statusText: ""
  : Object
  </code></pre>
  
  <p>The controller looks like this:</p>
  
  <pre><code>package com.pawsec.kitchen.controller;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RestController;
  
  import com.pawsec.kitchen.model.Guy;
  
  @RestController
  public class GuyController {
  
      @RequestMapping(value="/get/guy/{guyId}", method=RequestMethod.GET,
              headers={"Accept=application/json"})
      public Guy getGuy(@PathVariable("guyId") int guyId) {
          Guy someGuy = new Guy(guyId, "Walter Sobchak", 45);
          return someGuy;
      }
  
      @RequestMapping(value="/get/guys", method=RequestMethod.GET,
              headers={"Accept=application/json"})
      public List&lt;Guy&gt; getGuys() {
          Guy walter = new Guy(1, "Walter Sobchak", 45);
          Guy theDude = new Guy(2, "Jeffrey Lebowski", 42);
          Guy donny = new Guy(3, "Theodore Donald Kerabatsos", 39);
          List&lt;Guy&gt; guys = new ArrayList&lt;Guy&gt;();
          guys.add(walter);
          guys.add(theDude);
          guys.add(donny);
          return guys;
      }
  
  }
  </code></pre>
  
  <p>Strangely, if i call these two services from a browser, i get the correct Json structure for both the calls.</p>
  
  <p>When i run a mvn dependency:tree, the expected Jackson dependencies that come with a basic Boot Project are there.</p>
  
  <p>This is what the JavaScript code looks like:</p>
  
  <pre><code>return dispatch =&gt; {
          dispatch(fetchMenuStart());
          const url = 'https://boot.ourcompany.com:8443/get/guy/1'; 
          const headers = {
              headers: {
                  'Content-Type': 'application/json'
              }
          }
          axios.get(url, headers)
              .then(res =&gt; {
                  console.log(res); 
                  dispatch(fetchMenuSuccess(res.data.categories, res.data.restaurant));
              })
              .catch(error =&gt; {   
                  console.log("error", error);
                  const errorMsg = 'There was an error fetching the menu';
                  dispatch(fetchMenuFail(errorMsg)); 
              });
      };
  </code></pre>
  
  <p>Can anyone suggest what might be causing this or steps to test to figure out the issue?</p>
  
  <p>New javascript example code:</p>
  
  <pre><code>const doesNotWork = 'https://boot.exmpledomain.com:8443/get/guy/1'; 
  const doesWork = 'https://boot.exmpledomain.com:8443/get/guys'; 
  const headers = {
      headers: {
      'Content-Type': 'application/json;charset=UTF-8'
      }
  }
  axios.get(doesNotWork, headers)
      .then(res =&gt; {
          console.log(res); 
      })
      .catch(error =&gt; {   
          console.log("error", error);
          const errorMsg = 'There was an error fetching the menu';
      });
  </code></pre>