quarkusio/quarkus · error · IllegalStateException
Could not find MessageBodyWriter for ${entityClass} / ${enti
Error message
Could not find MessageBodyWriter for ${entityClass} / ${entityType} as ${mediaType} What it means
Thrown by StreamingUtil.serialiseEntity when the RESTEasy Reactive server needs to write an entity to bytes (e.g. streaming a response part) but no registered MessageBodyWriter can serialize the given Java type for the requested media type. It is a server-side serialization failure, meaning the resource's return type has no writer mapping for the negotiated content type. The runtime cannot produce a response body, so it aborts.
Source
Thrown at independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/StreamingUtil.java:82
MediaType mediaType = context.getResponseMediaType();
// FIXME: this should belong somewhere else as it's generic
@SuppressWarnings("unchecked")
MessageBodyWriter<Object>[] writers = (MessageBodyWriter<Object>[]) serialisers
.findWriters(null, entityClass, mediaType, RuntimeType.SERVER)
.toArray(ServerSerialisers.NO_WRITER);
StreamingOutputStream baos = new StreamingOutputStream();
boolean wrote = false;
for (MessageBodyWriter<Object> writer : writers) {
if (writer.isWriteable(entityClass, entityType, context.getAllAnnotations(), mediaType)) {
// FIXME: spec doesn't really say what headers we should use here
writer.writeTo(entity, entityClass, entityType, context.getAllAnnotations(), mediaType,
new QuarkusMultivaluedHashMap<>(), baos);
wrote = true;
break;
}
}
if (!wrote) {
throw new IllegalStateException(
"Could not find MessageBodyWriter for " + entityClass + " / " + entityType + " as " + mediaType);
}
return baos.toByteArray();
}
public static void setHeaders(ResteasyReactiveRequestContext context, ServerHttpResponse response,
List<PublisherResponseHandler.StreamingResponseCustomizer> customizers) {
// FIXME: spec says we should flush the headers when first message is sent or when the resource method returns, whichever
// happens first
if (!response.headWritten()) {
response.setStatusCode(Response.Status.OK.getStatusCode());
response.setResponseHeader(HttpHeaders.CONTENT_TYPE, context.getResponseContentType().toString());
response.setChunked(true);
for (int i = 0; i < customizers.size(); i++) {
customizers.get(i).customize(response);
}
}
}View on GitHub (pinned to e1c734241f)
Solutions
- Add a MessageBodyWriter or the extension providing one (e.g. quarkus-resteasy-reactive-jackson for JSON) and make sure @Produces matches (e.g. application/json).
- Check the entityClass in the message: if it's a wrapper like Multi/Uni or a raw type, return the unwrapped/parameterized type or register a custom writer.
- Register a custom Writer via @Provider implementing ServerMessageBodyWriter for the failing type/media type.
- If the type should never be serialized, fix the method signature so the correct body is returned instead of the internal object.
Example fix
// before
@GET @Produces(MediaType.APPLICATION_XML)
public MyPojo get() { return new MyPojo(); } // no XML writer
// after
@GET @Produces(MediaType.APPLICATION_JSON)
public MyPojo get() { return new MyPojo(); } // with quarkus-resteasy-reactive-jackson on classpath Defensive patterns
Strategy: validation
Validate before calling
if (!produces.contains(MediaType.APPLICATION_JSON)) { throw new ConfigurationException("No MessageBodyWriter for " + entity.getClass() + " with " + produces); } Try / catch
try { return response; } catch (IllegalStateException e) { if (e.getMessage().startsWith("Could not find MessageBodyWriter")) { log.errorf("Add a writer for %s", e.getMessage()); } throw e; } Prevention
- Declare @Produces matching every type you return
- Include the JSON extension (quarkus-resteasy-reactive-jackson) when returning POJOs
- Add an integration test asserting response content-type per endpoint
- Register custom writers with @Provider
When it happens
Trigger: A resource method (or multipart/streaming output path) returns an entity whose class has no @Produces-compatible MessageBodyWriter, or the mediaType requested (e.g. application/xml) has no writer registered for that entityClass/entityType (including generic Type information).
Common situations: Returning a POJO without a JSON mapper when only application/octet-stream is producible; missing quarkus-resteasy-reactive-jackson dependency; custom types without a registered writer; wrong @Produces annotation vs actual returned type.
Related errors
- Unknown JSON Value
- Failed to serialize content of type
- Could not find MessageBodyWriter for ${entityClass}
- Could not find MessageBodyWriter for ${entityClass} as ${med
- Could not find MessageBodyWriter for
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/b7705c622e1cc9bc.
Report an issue: GitHub.