title: JAX-RS (Reasteasy) Response.readEntity throws: IllegalStateException: RESTEASY003290: Entity is not backed by an input stream
body: <p>I have JUnit test of a method which send a JAX-RS <code>POST</code> call.
  To be independent from external resources I have mocked the REST client and said that a dummy response should be returned. Works great, no problem. But:</p>
  
  <p>When calling <code>myResponse.readEntity(String.class)</code> I always get the following Exception: </p>
  
  <blockquote>
    <p>java.lang.IllegalStateException: RESTEASY003290: Entity is not backed by an input stream</p>
  </blockquote>
  
  <p>Here is my code snippet which fails:</p>
  
  <pre><code>import com.google.gson.JsonObject;
  import com.google.gson.JsonPrimitive;
  import javax.ws.rs.core.MediaType;
  import javax.ws.rs.core.Response;
  import static org.hamcrest.CoreMatchers.is;
  import static org.hamcrest.MatcherAssert.assertThat;
  import org.junit.Test;
  
  public class SimpleTest {
  
      @Test
      public void testReadResponse() {
          final JsonObject responseContent = new JsonObject();
          responseContent.add("field", new JsonPrimitive("This is a JSON for testing."));
          final String expected = responseContent.toString();
          final Response.ResponseBuilder builder = Response.ok()
              .entity(responseContent.toString())
              .header("Content-Type", MediaType.APPLICATION_JSON);
          final Response dummyResponse = builder.build();
          final String result = dummyResponse.readEntity(String.class); // &lt;-- Exception is thrown here!
          assertThat("JSON Strings are not identical.", result, is(expected));
      }
  }
  </code></pre>
  
  <p>and the Stacktrace:</p>
  
  <pre><code>   java.lang.IllegalStateException: RESTEASY003290: Entity is not backed by an input stream
      at org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:230)
      at org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:219)
      at de.me.myproject.SimpleTest.testReadResponse(SimpleTest.java:43)
  </code></pre>
  
  <p>In my production code, which calls a not mocked REST API, it returns a automatically build response, where the <code>.readEntity(String.class)</code> method works fine.</p>