quarkusio/quarkus · error · ProcessingException

Request could not be mapped to type ${genericType != null ?

Error message

Request could not be mapped to type ${genericType != null ? genericType : entityType}

What it means

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.

Source

Thrown at independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/ResponseImpl.java:122

    }

    public InputStream getEntityStream() {
        return entityStream;
    }

    public void setEntityStream(InputStream entityStream) {
        this.entityStream = entityStream;
    }

    protected <T> T readEntity(Class<T> entityType, Type genericType, Annotation[] annotations) {
        // TODO: we probably need better state handling
        if (entity != null && entityType.isInstance(entity)) {
            // Note that this works if entityType is InputStream where we return it without closing it, as per spec
            return (T) entity;
        }
        checkClosed();
        // Spec says to throw this
        throw new ProcessingException(
                "Request could not be mapped to type " + (genericType != null ? genericType : entityType));
    }

    @Override
    public <T> T readEntity(Class<T> entityType) {
        return readEntity(entityType, entityType, null);
    }

    @SuppressWarnings("unchecked")
    @Override
    public <T> T readEntity(GenericType<T> entityType) {
        return (T) readEntity(entityType.getRawType(), entityType.getType(), null);
    }

    @Override
    public <T> T readEntity(Class<T> entityType, Annotation[] annotations) {
        return readEntity(entityType, entityType, annotations);
    }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Register the needed body reader — add quarkus-rest-jackson (or JSON-B) so application/json entities map to POJOs.
  2. Check response.getStatus() and read errors as String via readEntity(String.class) before mapping to a POJO.
  3. Ensure the requested type matches the received media type; only read the entity once or buffer with bufferEntity() first.
  4. Check the exception message for the exact target type and compare with the response's media type via getMediaType().

Example fix

// before
MyDto dto = response.readEntity(MyDto.class); // ProcessingException: no reader for JSON
// after (pom.xml)
<dependency>
  <groupId>io.quarkus</groupId>
  <artifactId>quarkus-rest-jackson</artifactId>
</dependency>
Defensive patterns

Strategy: try-catch

Validate before calling

if (response.getStatusInfo().getFamily() != Family.SUCCESSFUL) { String err = response.readEntity(String.class); throw new ApiException(err); }
if (response.getMediaType() == null || !response.getMediaType().isCompatible(MediaType.APPLICATION_JSON_TYPE)) { throw new ApiException("unexpected media type: " + response.getMediaType()); }

Type guard

boolean isReadableAs(javax.ws.rs.core.Response r, Class<?> type) { return r.hasEntity() && r.getMediaType() != null; }

Try / catch

try { return response.readEntity(MyDto.class); } catch (ProcessingException e) { throw new MappingException("Cannot map entity to MyDto, media type=" + response.getMediaType(), e); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/d8ee06512b0088b8. Report an issue: GitHub.