title: Spring HttpServerErrorException custom response body not being serialized
body: <p>I have a Controller like this example:</p>
  
  <pre><code>@RestController
  @RequestMapping(value = "/risk", produces = {MediaType.APPLICATION_JSON_VALUE})
  public class CalculationController {
      @RequestMapping(value = "/calculate", method = RequestMethod.POST)
      public CalculationResult calculate(InputFields i) {
         try {
             return calcService.calculate(i);
         } catch (CustomException custEx) {
              throw new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, 
                                                  null,
                                                  null, 
                                                  getReportLogAsBytes(custEx), //for some reason not working when serialized in Json
                                                  Charset.defaultCharset());
          }       
      }
  
      private byte[] getReportLogAsBytes(CustomException e) {
          try {
              return objectMapper.writeValueAsBytes(e.getReportLog()); //
          } catch (JsonProcessingException e1) {
              throw new RuntimeException("Unable to serialize Simulation report log to bytes ", e1);
          }
      }
  
      class CustomException extends Exception {
  
          private List&lt;String&gt; reportLog;
  
          public CustomException(List&lt;String&gt; reportLog) {
              super();
              this.setReportLog(reportLog);
          }
  
          public List&lt;String&gt; getReportLog() {
              return reportLog;
          }
  
          public void setReportLog(List&lt;String&gt; reportLog) {
              this.reportLog = reportLog;
          }       
      }
  }
  </code></pre>
  
  <p>When posting the inputs to the controller and a CustomException occurs, I instantiate <strong>HttpServerErrorException</strong> using the constructor that accepts a byte array for <strong>responseBody</strong>. I basically give it a list of String error messages converted to byte array. </p>
  
  <p><strong>The problem is the response body still does not show the list of errors messages</strong> I passed to it. I tried looking for examples on using HttpServerErrorException  with response body but cannot seem to find any... Any help would be greatly appreciated.</p>