{"record":{"id":"d8ee06512b0088b8","repo":"quarkusio/quarkus","slug":"request-could-not-be-mapped-to-type-generictype","errorCode":null,"errorMessage":"Request could not be mapped to type ${genericType != null ? genericType : entityType}","messagePattern":"Request could not be mapped to type (.+?)","errorType":"exception","errorClass":"ProcessingException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/ResponseImpl.java","lineNumber":122,"sourceCode":"    }\n\n    public InputStream getEntityStream() {\n        return entityStream;\n    }\n\n    public void setEntityStream(InputStream entityStream) {\n        this.entityStream = entityStream;\n    }\n\n    protected <T> T readEntity(Class<T> entityType, Type genericType, Annotation[] annotations) {\n        // TODO: we probably need better state handling\n        if (entity != null && entityType.isInstance(entity)) {\n            // Note that this works if entityType is InputStream where we return it without closing it, as per spec\n            return (T) entity;\n        }\n        checkClosed();\n        // Spec says to throw this\n        throw new ProcessingException(\n                \"Request could not be mapped to type \" + (genericType != null ? genericType : entityType));\n    }\n\n    @Override\n    public <T> T readEntity(Class<T> entityType) {\n        return readEntity(entityType, entityType, null);\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    @Override\n    public <T> T readEntity(GenericType<T> entityType) {\n        return (T) readEntity(entityType.getRawType(), entityType.getType(), null);\n    }\n\n    @Override\n    public <T> T readEntity(Class<T> entityType, Annotation[] annotations) {\n        return readEntity(entityType, entityType, annotations);\n    }","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/ResponseImpl.java#L104-L140","documentation":"ResponseImpl.readEntity() throws ProcessingException when the response entity cannot be mapped to the requested Java type. In this implementation it is thrown when no MessageBodyReader can handle the entity for the target type — e.g. the entity is a different media type or already consumed/unsupported. It does NOT necessarily mean the response was an HTTP error.","triggerScenarios":"Calling response.readEntity(Foo.class) when the entity's media type has no registered reader for Foo (e.g. reading JSON into a POJO without a JSON provider on the classpath), or the genericType/entityType is incompatible with the received representation.","commonSituations":"Missing Jackson/JSON-B extension dependency so application/json cannot be deserialized; reading a String-typed error body into a POJO; calling readEntity twice on a non-buffered response so the stream is already consumed.","solutions":["Register the needed body reader — add quarkus-rest-jackson (or JSON-B) so application/json entities map to POJOs.","Check response.getStatus() and read errors as String via readEntity(String.class) before mapping to a POJO.","Ensure the requested type matches the received media type; only read the entity once or buffer with bufferEntity() first.","Check the exception message for the exact target type and compare with the response's media type via getMediaType()."],"exampleFix":"// before\nMyDto dto = response.readEntity(MyDto.class); // ProcessingException: no reader for JSON\n// after (pom.xml)\n<dependency>\n  <groupId>io.quarkus</groupId>\n  <artifactId>quarkus-rest-jackson</artifactId>\n</dependency>","handlingStrategy":"try-catch","validationCode":"if (response.getStatusInfo().getFamily() != Family.SUCCESSFUL) { String err = response.readEntity(String.class); throw new ApiException(err); }\nif (response.getMediaType() == null || !response.getMediaType().isCompatible(MediaType.APPLICATION_JSON_TYPE)) { throw new ApiException(\"unexpected media type: \" + response.getMediaType()); }","typeGuard":"boolean isReadableAs(javax.ws.rs.core.Response r, Class<?> type) { return r.hasEntity() && r.getMediaType() != null; }","tryCatchPattern":"try { return response.readEntity(MyDto.class); } catch (ProcessingException e) { throw new MappingException(\"Cannot map entity to MyDto, media type=\" + response.getMediaType(), e); }","preventionTips":["Add the JSON provider extension (quarkus-rest-jackson / JSON-B) so POJO mapping works","Check status and media type before mapping the entity","Call readEntity exactly once or bufferEntity() first","Read unexpected bodies as String for diagnostics"],"tags":["jax-rs","client","entity-mapping","messagebodyreader"],"backgroundTag":"entity-read-processing-exception","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}