title: Custom JSON response with Spring Boot
body: <p>I developed a spring boot application, in the controller i have a method that returns a list of products</p>
  
  <pre><code>@GetMapping
  public ResponseEntity&lt;List&lt;Product&gt;&gt; listAllProducts() {
      List&lt;Product&gt; products = productRepository.findAll();
      if (products.isEmpty()) {
          return new ResponseEntity&lt;List&lt;Product&gt;&gt;(HttpStatus.NO_CONTENT);
      }
      return new ResponseEntity&lt;List&lt;Product&gt;&gt;(products, HttpStatus.OK);
  }
  </code></pre>
  
  <p>the result is as follows:</p>
  
  <pre><code>[
  {
      "name": "Ruby on Rails Baseball Jersey",
      "description": null,
      "price": 19.99,
      "slug": "ruby-on-rails-tote"
  },
  {
      "name": "Ruby on Rails Baseball Jersey",
      "description": null,
      "price": 19.99,
      "slug": "ruby-on-rails-tote"
  },
  {
      "name": "Ruby on Rails Baseball Jersey",
      "description": null,
      "price": 19.99,
      "slug": "ruby-on-rails-tote"
  }
  ]
  </code></pre>
  
  <p>How can i modify the method listAllProducts so that the result comes like this</p>
  
  <pre><code>{
  "products": [
      {
          "name": "Ruby on Rails Baseball Jersey",
          "description": null,
          "price": 19.99,
          "slug": "ruby-on-rails-tote"
      },
      {
          "name": "Ruby on Rails Baseball Jersey",
          "description": null,
          "price": 19.99,
          "slug": "ruby-on-rails-tote"
      },
      {
          "name": "Ruby on Rails Baseball Jersey",
          "description": null,
          "price": 19.99,
          "slug": "ruby-on-rails-tote"
      }
  ]
  }
  </code></pre>