title: Use reasteasy interface for client proxy and server implementation typesafe
body: <p>I can declare an interface for a jax-rs webservice like this:</p>
  
  <pre><code>@Path("/foo")
  public interface FooRestService {
      class Foo {
          // DTO-Klasse
      }
  
      @GET
      @Produces("application/json")
      @Path("/list")
      List&lt;Foo&gt; list();
  }
  </code></pre>
  
  <p>I then can use this interface for both the webservice implementation and the client proxy like this:</p>
  
  <pre><code>public class FooRestServiceImpl implements FooRestService {
      @Override
      public List&lt;Foo&gt; list() {
          // ...
      }
  }
  </code></pre>
  
  <p>and on the client...</p>
  
  <pre><code>FooRestService service = new ResteasyClientBuilder().build()
      .proxy(FooRestService.class);
  List&lt;Foo&gt; foos = service.list();
  System.out.println(foos);
  </code></pre>
  
  <p>However, if I want to include http-metadata (status codes, headers etc.) in the response, I have to extract the actual return type in a non-typesafe manner, for example:</p>
  
  <pre><code>public class FooRestServiceImpl implements FooRestService {
      @Override
      public Response list() {
          return Response.ok().entity(/* ... */).build();
          // ...
      }
  }
  </code></pre>
  
  <p>and on the client...</p>
  
  <pre><code>Response response = service.list();
  int status = response.getStatus();
  final GenericType&lt;List&lt;Foo&gt;&gt; type = new GenericType&lt;List&lt;Foo&gt;&gt;() {};
  List&lt;Foo&gt; foos = response.readEntity(type);
  </code></pre>
  
  <p>If I'd use the interface client-side only, I could use a <a href="http://docs.jboss.org/resteasy/docs/3.5.0.Final/userguide/html/RESTEasy_Client_Framework.html#Response_proxies" rel="nofollow noreferrer">Response proxy</a> like this:</p>
  
  <pre><code>@Path("/foo")
  public interface FooRestService {
      @ResponseObject
      interface CustomResponse {
          @Status
          int status();
  
          @Body
          List&lt;Foo&gt; body();
      }
  
      @GET
      @Produces("application/json")
      @Path("/list")
      CustomResponse list();
  }
  </code></pre>
  
  <p>However, I can't properly use this interface for the server-side implementation, since <code>ResponseObject</code> is to be used client-side only with an interface for automatic mapping from generic HTTP-responses, not as a return type on the server side. Is there a way to specify a typesafe return object in the interface, so that it can be used for both the server implementation and the client proxy?</p>