title: Spring Boot - Returning JSON with array of objects
body: <p>Using this <a href="https://stackoverflow.com/a/44839954/919480">answer</a> as a hint, I developed a Spring Boot controller for <code>/greetings</code> to return greeting in different languages in JSON. </p>
  
  <p>While I am getting the output in the format (array of objects) I wanted, can you please let me know if there is a better way?</p>
  
  <pre class="lang-java prettyprint-override"><code>package com.example.demo;
  
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.RestController;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  
  @RestController
  public class GreetingController {
      @GetMapping("/greetings")
      public HashMap&lt;String, Object&gt; getGreeting() {
          ArrayList&lt;Object&gt; al = new ArrayList&lt;Object&gt;();
          HashMap&lt;String, String&gt; map1 = new HashMap&lt;String, String&gt;();
          map1.put("en", "Greetings!");
          al.add(map1);
          HashMap&lt;String, String&gt; map2 = new HashMap&lt;&gt;();
          map2.put("hi", "Namaste!");
          al.add(map2);
          //
          HashMap&lt;String, Object&gt; finalMap = new HashMap&lt;&gt;();
          finalMap.put("all", al);
          return finalMap;
      }
  }
  </code></pre>
  
  <p>Received (valid) output:</p>
  
  <pre><code>{
      "all": [
          {
              "en": "Greetings!"
          },
          {
              "hi": "Namaste!"
          }
      ]
  }
  </code></pre>