title: Spring Boot custom exception within an Rest Service
body: <p>I have defined a global exception handling in my Spring Boot based Rest service:</p>
  
  <pre><code>@ControllerAdvice
  public class GlobalExceptionController {
  
      private final Logger LOG = LoggerFactory.getLogger(getClass());
  
      @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR, reason = "Internal application error")
      @ExceptionHandler({ServiceException.class})
      @ResponseBody
      public ServiceException serviceError(ServiceException e) {
          LOG.error("{}: {}", e.getErrorCode(), e.getMessage());
          return e;
      }
  }
  </code></pre>
  
  <p>and a custom ServiceException:</p>
  
  <pre><code>public class ServiceException extends RuntimeException {
  
      private static final long serialVersionUID = -6502596312985405760L;
  
      private String errorCode;
  
      public ServiceException(String message, String errorCode, Throwable cause) {
          super(message, cause);
          this.errorCode = errorCode;
      }
  
      // other constructors, getter and setters omitted
  }
  </code></pre>
  
  <p>so far so good, when an exception is fired the controller works as it should and respond with:</p>
  
  <pre><code>{
     "timestamp": 1413883870237,
     "status": 500,
     "error": "Internal Server Error",
     "exception": "org.example.ServiceException",
     "message": "somthing goes wrong",
     "path": "/index"
  }
  </code></pre>
  
  <p>but the field <strong>errorCode</strong> isn't shown in the JSON response.</p>
  
  <p>So how can I define a custom exception response in my application.</p>