title: Creating Java Spring Boot endpoint to obtain list of objects as json
body: <p>I'm trying to create an endpoint that returns a list of objects as a JSON.</p>
  
  <p>The current object structure is as follows:</p>
  
  <pre><code>units: [
          {
           id: #,
           order: #,
           name: ""
           concepts: [
                      {
                       id: #
                       name: ""
                      },
                      ...
           ]
          },
          ...
  ]
  </code></pre>
  
  <p>A list of units which have 4 attributes, one of them being another list of objects with 2 otehr attributes. This is kind of the result I'm looking to obtain.</p>
  
  <p>I was currently trying to do the following in my <code>UnitController</code>:</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.GET, produces = "application/json; charset=UTF-8")
  public @ResponseBody List&lt;Unit&gt; getUnits() {
      return unitService.findAll();
  }
  </code></pre>
  
  <p>But whenever I run the app and try <code>curl localhost:8080/units</code>, I get nothing. Could this be because of another method I have in the controller, like this one:</p>
  
  <pre><code>@RequestMapping("")
  public String index(Map&lt;String, Object&gt; model) {
      List&lt;Unit&gt; units = unitService.findAll();
      model.put("units", units);
      return "units/index";
  }
  </code></pre>
  
  <p>Could someone kindly help me through this and tell me what I'm doing wrong? I'd really appreciate it.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Ok so I moved the annotation on top of the class</p>
  
  <pre><code>@Controller
  @RequestMapping(value = "/units", method = RequestMethod.GET, produces = "application/json; charset=UTF-8")
  public class UnitController extends BaseController {
  ...
  }
  </code></pre>
  
  <p>And tried the endpoint like this:</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.GET, value = "/units.json")
  public @ResponseBody List&lt;Unit&gt; getUnits() {
      return unitService.findAll();
  }
  </code></pre>
  
  <p>But it <code>curl localhost:8080/units.json</code> is still giving me no response.</p>
  
  <p>Also forgot to mention that my <code>application.properties</code> file doesn't have a <code>server.contextPath</code> property.</p>