title: Intecepting Rest Controller responses
body: <p>I am building a REST service using spring boot. My controller is annotated with <code>@RestController</code>. For debugging purposes I want to intercept the <code>ResponseEntity</code> generated by each of the controller methods (if possible). Then I wish to construct a new <code>ResponseEntity</code> that is somewhat based on the one generated by the controller. Finally the new generated <code>ResponseEntity</code> will replace the one generated by the controller and be returned as part of the response.</p>
  
  <p>I only want to be able to do this when debugging the application. Otherwise I want the standard response generated by the controller returned to the client.</p>
  
  <p>For example I have the controller</p>
  
  <pre><code>@RestController
  class SimpleController
  
      @RequestMapping(method=RequestMethod.GET, value="/getname")
      public NameObject categories()
      {
          return new NameObject("John Smith");
      }
  }
  
  class NameObject{
      private String name;
      public NameObject(name){
          this.name = name;
      }
      public String getName(){ return name; }
  }
  </code></pre>
  
  <p>This will generate the response:</p>
  
  <pre><code>{"name" : "John Smith"}
  </code></pre>
  
  <p>But I would like to change the response to include status info of the actual response e.g:</p>
  
  <pre><code>{"result": {"name" : "John Smith"}, "status" : 200 }
  </code></pre>
  
  <p>Any pointers appreciated.</p>