quarkusio/quarkus · error · InternalServerErrorException
Could not find MessageBodyWriter for
Error message
Could not find MessageBodyWriter for
What it means
DynamicEntityWriter is used when no single writer was fixed at build time for the response entity. At runtime none of the candidate MessageBodyWriters could serialize the entity class for the negotiated media type, so RESTEasy Reactive throws InternalServerErrorException (500) because the application promised a body it cannot render.
Source
Thrown at independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/serialization/DynamicEntityWriter.java:123
} else {
serverSerializersMediaType = selectedMediaType;
context.setResponseContentType(selectedMediaType);
// this will be used as the fallback if Response does NOT contain a type
context.serverResponse().addResponseHeader(HttpHeaders.CONTENT_TYPE,
context.getResponseContentType().toString());
}
}
} else {
writers = serialisers
.findWriters(null, entity.getClass(), producesMediaType.getMediaType(), RuntimeType.SERVER)
.toArray(ServerSerialisers.NO_WRITER);
}
for (MessageBodyWriter<?> w : writers) {
if (ServerSerialisers.invokeWriter(context, entity, w, serialisers, serverSerializersMediaType)) {
return;
}
}
throw new InternalServerErrorException("Could not find MessageBodyWriter for " + entity.getClass(),
Response.serverError().build());
}
}
View on GitHub (pinned to e1c734241f)
Solutions
- Add the serializer extension: quarkus-rest-jackson (or quarkus-rest-jsonb) so POJOs get a writer.
- Annotate the entity class with @RegisterForReflection for native-image serialization support.
- Declare a concrete return type (e.g. MyDto instead of Object) so build-time writer selection can wire a writer.
- Check the negotiated media type: ensure the method's @Produces matches what the client Accepts and a writer exists for it.
- Return jakarta.ws.rs.core.Response with an explicit entity/type if dynamic typing is required.
Example fix
// before
@GET @Path("/x")
public Object get() { return new MyDto(); } // no writer for Object
// after
@GET @Path("/x")
@Produces(MediaType.APPLICATION_JSON)
public MyDto get() { return new MyDto(); } Defensive patterns
Strategy: try-catch
Validate before calling
// ensure a writer exists before returning the entity
if (entityManagerFactory == null) { /* e.g. */ }
// check JSON extension present: assert application can serialize entity
ObjectMapper om = new ObjectMapper();
om.writeValue(new StringWriter(), myEntity); // throws if no serializer can handle it Type guard
static boolean hasKnownWriter(Object entity) {
return entity instanceof String || entity instanceof byte[]
|| entity != null && (entity.getClass().isAnnotationPresent(RegisterForReflection.class)
|| entity.getClass().getSimpleName().endsWith("Dto"));
} Try / catch
try {
return Response.ok(entity).build();
} catch (InternalServerErrorException e) {
if (e.getMessage().contains("Could not find MessageBodyWriter")) {
log.errorf("No writer for %s — add quarkus-rest-jackson or @RegisterForReflection", entity.getClass());
}
throw e;
} Prevention
- Always include quarkus-rest-jackson or quarkus-rest-jsonb for POJO returns.
- Annotate serialization-visible classes with @RegisterForReflection (native).
- Return concrete types, not Object.
- Keep @Produces aligned with installed writers; test each endpoint's response in CI.
When it happens
Trigger: A resource method returns an Object/unknown type (or Uni<Response> with a bare entity) whose runtime class has no registered MessageBodyWriter compatible with the response media type.
Common situations: Returning arbitrary POJOs without @RegisterForReflection / without a JSON serializer registered (missing quarkus-rest-jackson/quarkus-rest-jsonb dependency); returning File/String with an incompatible Accept type; returning raw collections where the element writer is not registered.
Related errors
- Could not find MessageBodyWriter for
- Could not find MessageBodyWriter for
- Could not find MessageBodyWriter for
- Failed to serialize content of type
- Could not find MessageBodyWriter for ${entityClass}
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/58c5f6247bcb2b2a.
Report an issue: GitHub.