quarkusio/quarkus · error · IllegalStateException
Could not find MessageBodyWriter for ${entityClass} as ${med
Error message
Could not find MessageBodyWriter for ${entityClass} as ${mediaType} What it means
MultipartMessageBodyWriter.writeEntity throws when writing one part of an outgoing multipart response and no MessageBodyWriter exists for that part's entity class with the target media type. Like the top-level writer lookup failure, but scoped to a single part of the multipart entity. The response cannot be serialized and fails with IllegalStateException.
Source
Thrown at independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/multipart/MultipartMessageBodyWriter.java:303
MessageBodyWriter<Object>[] writers = (MessageBodyWriter<Object>[]) serializers
.findWriters(null, entityClass, mediaType, RuntimeType.SERVER)
.toArray(ServerSerialisers.NO_WRITER);
boolean wrote = false;
for (MessageBodyWriter<Object> writer : writers) {
if (writer.isWriteable(entityClass, entityType, Serialisers.NO_ANNOTATION, mediaType)) {
try (NoopCloseAndFlushOutputStream writerOutput = new NoopCloseAndFlushOutputStream(os)) {
// FIXME: spec doesn't really say what headers we should use here
writer.writeTo(entity, entityClass, entityType, Serialisers.NO_ANNOTATION, mediaType,
new QuarkusMultivaluedHashMap<>(), writerOutput);
wrote = true;
}
break;
}
}
if (!wrote) {
throw new IllegalStateException("Could not find MessageBodyWriter for " + entityClass + " as " + mediaType);
}
}
private String generateBoundary() {
return UUID.randomUUID().toString();
}
private void appendBoundaryIntoMediaType(ResteasyReactiveRequestContext requestContext, String boundary,
MediaType mediaType) {
MediaType mediaTypeWithBoundary = new MediaType(mediaType.getType(), mediaType.getSubtype(),
Collections.singletonMap(BOUNDARY_PARAM, boundary));
requestContext.setResponseContentType(mediaTypeWithBoundary);
// this is a total hack, but it's needed to make RestResponse<MultipartFormDataOutput> work properly
requestContext.serverResponse().setResponseHeader(CONTENT_TYPE, mediaTypeWithBoundary.toString());
if (requestContext.getResponse().isCreated()) {
requestContext.getResponse().get().getHeaders().remove(CONTENT_TYPE);
}View on GitHub (pinned to e1c734241f)
Solutions
- Add the required writer (e.g. quarkus-resteasy-reactive-jackson) or set @PartType(MediaType.APPLICATION_JSON) with a mapper present.
- Use a supported part type (String, FileUpload, byte[]) or register a custom MessageBodyWriter for the part class.
- Verify the @PartType annotation on each MultipartOutput field matches a writer-capable media type.
- Register a Writer via @Provider for the custom part type.
Example fix
// before
public class Output { public MyPojo part; } // no writer for MyPojo as text/plain
// after
public class Output {
@PartType(MediaType.APPLICATION_JSON)
public MyPojo part;
} Defensive patterns
Strategy: validation
Validate before calling
for (Field f : output.getClass().getDeclaredFields()) { PartType pt = f.getAnnotation(PartType.class); if (pt == null) throw new ConfigurationException("missing @PartType on " + f.getName()); } Try / catch
try { writeMultipart(out); } catch (IllegalStateException e) { if (e.getMessage().startsWith("Could not find MessageBodyWriter")) { log.error("register writer or fix @PartType: " + e.getMessage()); } throw e; } Prevention
- Annotate every MultipartOutput field with @PartType
- Keep the Jackson extension on the classpath for object parts
- Restrict part fields to supported types (String, FileUpload, byte[], POJOs with writers)
- Test multipart endpoints returning files
When it happens
Trigger: A resource returns a MultipartOutput (or List<FileUpload>-style multipart response) whose part object type has no MessageBodyWriter registered for the @PartType/@@Produces media type assigned to that part.
Common situations: Custom POJO parts without a matching writer for application/json or text/plain; missing Jackson extension so Object parts cannot be written; wrong @PartType on the output part field.
Related errors
- Failed to serialize content of type
- Could not find MessageBodyWriter for ${entityClass} / ${enti
- Form value is a file
- Form value is a string
- Media type '" + mediaType + "' in multipart request is not s
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/57cf5b2255bc063a.
Report an issue: GitHub.