title: How to overwrite the default JSON response in Spring boot
body: <p>My spring boot application returning below json response when controller responds with 400-BadRequest.</p>
  
  <pre><code>{
    "readyState": 4,
    "responseText": "{\r\n  \"success\" : false,\r\n  \"projects\" :null,\r\n  \"httpStatusCode\" : \"400\",\r\n  \"message\" : \"Request  Processing failed.\",\r\n  \"requestErrors\" : [ {\r\n    \"error\" : \"platform required.\"\r\n  }, {\r\n    \"error\" : \"id required.\"\r\n  }, {\r\n    \"error\" : \"name required.\"\r\n  } ]\r\n}",
  "responseJSON": {
  "success": false,
  "projects": null,
  "httpStatusCode": "400",
  "message": "Request Processing failed.",
  "requestErrors": [
    {
      "error": "platform required."
    },
    {
      "error": "id required."
    },
    {
      "error": "name required."
    }
  ]
  },
   "status": 400,
   "statusText": "Bad Request" 
  }
  </code></pre>
  
  <p>But here i dont want to see json elements <code>responseText</code>, <code>status</code>, and <code>statusText</code>, since my JSON object itself having these information.</p>
  
  <p>Here is my <code>CustomErrorAttributes</code> class.</p>
  
  <pre><code>public class CustomErrorAttribute implements ErrorAttributes {
  @Override
  public Map&lt;String, Object&gt; getErrorAttributes(RequestAttributes requestAttributes, boolean includeStackTrace) {
      Map&lt;String, Object&gt; errorAttributes = new LinkedHashMap&lt;String, Object&gt;();
      errorAttributes.put("timestamp", new Date());
      return errorAttributes;
  }
  
  @Override
  public Throwable getError(RequestAttributes requestAttributes) {
      return new IllegalStateException("Illegal State of the request.");
  }
  }
  </code></pre>
  
  <p>Java Config:</p>
  
  <pre><code>@Bean
  public ErrorAttributes customErrorAttribute(){
      return new CustomErrorAttribute();
  }
  </code></pre>
  
  <p>I tried with registering custom implementation of <code>ErrorAttributes</code> as <code>@Bean</code> as specified <a href="https://stackoverflow.com/questions/28350445/where-does-the-default-json-errors-response-in-spring-boot-starter-web-comes-fro">here</a>  </p>
  
  <p>But no luck, please any help. Thanks.</p>