title: Spring REST Controller returns empty JSON. Iterable data structure. Why?
body: <p>I realize a very similar question was asked and closed because it wasn't specific enough and didn't specify outcomes.  <a href="https://stackoverflow.com/questions/39914710/spring-rest-controller-returns-json-with-empty-data">Closed Off Topic</a></p>
  
  <p>Problem: JSON being returned from REST controller is empty.  Verified data exists and is in the Iterable.</p>
  
  <p>Expected Outcome:  A JSON Array containing objects would be returned.</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.codeexcursion&lt;/groupId&gt;
    &lt;organization&gt;
      &lt;name&gt;Chris Lynch&lt;/name&gt;
    &lt;/organization&gt;
    &lt;version&gt;1.00.000&lt;/version&gt;
    &lt;artifactId&gt;work-tracking&lt;/artifactId&gt;
    &lt;packaging&gt;jar&lt;/packaging&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;1.5.10.RELEASE&lt;/version&gt;
    &lt;/parent&gt;
  
    &lt;properties&gt;
      &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
      &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
    &lt;/properties&gt;
  
  
    &lt;name&gt;Work Tracking&lt;/name&gt;
  
    &lt;inceptionYear&gt;2017&lt;/inceptionYear&gt;
  
    &lt;developers&gt;
      &lt;developer&gt;
        &lt;id /&gt;
        &lt;name&gt;Chris Lynch&lt;/name&gt;
        &lt;email&gt;chrislynch42@yahoo.com&lt;/email&gt;
        &lt;timezone&gt;-4&lt;/timezone&gt;
        &lt;roles&gt;
          &lt;role&gt;Chief cook and bottle washer.&lt;/role&gt;
        &lt;/roles&gt;
      &lt;/developer&gt;
    &lt;/developers&gt;
  
    &lt;dependencies&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;org.mockito&lt;/groupId&gt;
        &lt;artifactId&gt;mockito-all&lt;/artifactId&gt;
        &lt;version&gt;1.10.19&lt;/version&gt;
        &lt;scope&gt;test&lt;/scope&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;version&gt;1.5.10.RELEASE&lt;/version&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;version&gt;1.5.10.RELEASE&lt;/version&gt;
        &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
        &lt;version&gt;1.5.10.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-data-rest&lt;/artifactId&gt;
        &lt;version&gt;1.5.10.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
        &lt;groupId&gt;org.apache.derby&lt;/groupId&gt;
        &lt;artifactId&gt;derby&lt;/artifactId&gt;
        &lt;version&gt;10.13.1.1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;junit&lt;/groupId&gt;
        &lt;artifactId&gt;junit&lt;/artifactId&gt;
        &lt;version&gt;4.12&lt;/version&gt;
        &lt;scope&gt;test&lt;/scope&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;mainClass&gt;com.codeexcursion.Application&lt;/mainClass&gt;
          &lt;/configuration&gt;
        &lt;/plugin&gt;
      &lt;/plugins&gt;
    &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>Entity</p>
  
  <pre><code>//Package and import Omitted
  
  @Entity
  public class Category {
  
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
  
    private Long parentId;
  
    private String title;
  
    private String description;
  
    protected Category() {
    }
  
    public Category(final String title, String description) {
      this(0L, title, description);
    }
  
    public Category(Long parentId, final String title, String description) {
      if (parentId == null) {
        parentId = 0L;
      }
      if (title == null || title.trim().isEmpty()) {
        throw new IllegalArgumentException("Title may not be null or empty.");
      }
      if (description == null) {
        description = "";
      }
      this.parentId = parentId;
      this.title = title;
      this.description = description;
    }
  
    @Override
    public String toString() {
      return "id = " + id + "; parentId=" + parentId + "; title=" + title + "; description=" + description;
    }
  
  
  }
  </code></pre>
  
  <p>Resource</p>
  
  <pre><code>//Package and import Omitted
  
  @Repository
  public interface CategoryCRUD  extends CrudRepository&lt;Category, Long&gt; {
    List&lt;Category&gt; findByTitle(String title);
  }
  </code></pre>
  
  <p>Rest Controller</p>
  
  <pre><code>//Package and import Omitted
  
  @RestController
  @RequestMapping("/categories")
  public class CategoryController {
  
    @Autowired
    private CategoryCRUD categoryCRUD;  
  
  
    @RequestMapping(value = "", method = RequestMethod.GET)
    public @ResponseBody Iterable&lt;Category&gt; list() {
      System.out.println("findAll");
      categoryCRUD.findAll().forEach((category) -&gt; {
        System.out.println("category=" + category);
      });    
      return categoryCRUD.findAll();
    }
  
    private List&lt;Category&gt; findAll() {
      final Iterable&lt;Category&gt; data = categoryCRUD.findAll();
      List&lt;Category&gt; returnList = new ArrayList&lt;&gt;();
      data.forEach(returnList::add);
      return returnList; 
    }
  
  
  }
  </code></pre>