{"record":{"id":"58c5f6247bcb2b2a","repo":"quarkusio/quarkus","slug":"could-not-find-messagebodywriter-for","errorCode":null,"errorMessage":"Could not find MessageBodyWriter for ","messagePattern":"Could not find MessageBodyWriter for ","errorType":"http","errorClass":"InternalServerErrorException","httpStatus":500,"severity":"error","filePath":"independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/serialization/DynamicEntityWriter.java","lineNumber":123,"sourceCode":"                } else {\n                    serverSerializersMediaType = selectedMediaType;\n                    context.setResponseContentType(selectedMediaType);\n                    // this will be used as the fallback if Response does NOT contain a type\n                    context.serverResponse().addResponseHeader(HttpHeaders.CONTENT_TYPE,\n                            context.getResponseContentType().toString());\n                }\n            }\n        } else {\n            writers = serialisers\n                    .findWriters(null, entity.getClass(), producesMediaType.getMediaType(), RuntimeType.SERVER)\n                    .toArray(ServerSerialisers.NO_WRITER);\n        }\n        for (MessageBodyWriter<?> w : writers) {\n            if (ServerSerialisers.invokeWriter(context, entity, w, serialisers, serverSerializersMediaType)) {\n                return;\n            }\n        }\n        throw new InternalServerErrorException(\"Could not find MessageBodyWriter for \" + entity.getClass(),\n                Response.serverError().build());\n    }\n\n}\n","sourceCodeStart":105,"sourceCodeEnd":128,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/serialization/DynamicEntityWriter.java#L105-L128","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n@GET @Path(\"/x\")\npublic Object get() { return new MyDto(); } // no writer for Object\n// after\n@GET @Path(\"/x\")\n@Produces(MediaType.APPLICATION_JSON)\npublic MyDto get() { return new MyDto(); }","handlingStrategy":"try-catch","validationCode":"// ensure a writer exists before returning the entity\nif (entityManagerFactory == null) { /* e.g. */ }\n// check JSON extension present: assert application can serialize entity\nObjectMapper om = new ObjectMapper();\nom.writeValue(new StringWriter(), myEntity); // throws if no serializer can handle it","typeGuard":"static boolean hasKnownWriter(Object entity) {\n    return entity instanceof String || entity instanceof byte[]\n        || entity != null && (entity.getClass().isAnnotationPresent(RegisterForReflection.class)\n            || entity.getClass().getSimpleName().endsWith(\"Dto\"));\n}","tryCatchPattern":"try {\n    return Response.ok(entity).build();\n} catch (InternalServerErrorException e) {\n    if (e.getMessage().contains(\"Could not find MessageBodyWriter\")) {\n        log.errorf(\"No writer for %s — add quarkus-rest-jackson or @RegisterForReflection\", entity.getClass());\n    }\n    throw e;\n}","preventionTips":["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."],"tags":["resteasy-reactive","serialization","messagebodywriter","http-500"],"backgroundTag":"no-messagebodywriter-for-entity","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"}