title: Spring Controller - HashMap Return
body: <p>I have a very basic REST controller...</p>
  
  <pre><code>@RestController
  @CrossOrigin(origins = "*")
  @RequestMapping(value = "/signKey", produces = "application/json")
  public class SignKeyController {
  
  @Autowired
  private SignKeyService signKeyService;
  
  @GetMapping(value = "/generate")
  public ResponseEntity&lt;?&gt; generateSignKey() {
      String signKeyToken = signKeyService.generateNewToken();
      Map&lt;String, String&gt; data = new HashMap&lt;&gt;();
      data.put("signKey", signKeyToken);
      return new ResponseEntity&lt;&gt;(data, HttpStatus.OK);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>returns </p>
  
  <pre><code>{
  "signKey": "_IjAY736MvwKZLtoJHrhNaD4MUL2r0Al"
  }
  </code></pre>
  
  <p>But because I want to return a json object to the frontend, instead of only a string I created an hashmap.
  This code works fine but I feel like there should be a better way...</p>
  
  <p>In this case I don't want to create models or anything. This is a simple return of a String. Do I really need to keep creating HashMaps in my controllers which only return some data that is not in any model?</p>
  
  <p>Any help?</p>