{"record":{"id":"59206432094918aa","repo":"quarkusio/quarkus","slug":"could-not-find-messagebodywriter-for-entity-getc","errorCode":null,"errorMessage":"Could not find MessageBodyWriter for ${entity.getClass()}","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/jaxrs/WriterInterceptorContextImpl.java","lineNumber":55,"sourceCode":"        super(context, annotations, type, genericType, mediaType, serialisers);\n        this.interceptors = interceptors;\n        this.writer = writer;\n        this.entity = entity;\n        this.headers.putAll(headers);\n    }\n\n    @Override\n    public void proceed() throws IOException, WebApplicationException {\n        Response response = context.getResponse().get();\n        // this is needed in order to avoid having the headers written out twice\n        context.serverResponse().setPreCommitListener(null);\n        if (index == interceptors.length) {\n            MessageBodyWriter effectiveWriter = writer;\n            if (rediscoveryNeeded) {\n                List<MessageBodyWriter<?>> newWriters = serialisers.findWriters(null, entity.getClass(), mediaType,\n                        RuntimeType.SERVER);\n                if (newWriters.isEmpty()) {\n                    throw new InternalServerErrorException(\"Could not find MessageBodyWriter for \" + entity.getClass(),\n                            Response.serverError().build());\n                }\n                effectiveWriter = newWriters.get(0);\n            }\n            context.setResult(Response.fromResponse(response).replaceAll(headers).build());\n            ServerSerialisers.encodeResponseHeaders(context);\n            // this must be done AFTER encoding the headers, otherwise the HTTP response gets all messed up\n            effectiveWriter.writeTo(entity, type, genericType,\n                    annotations, mediaType != null ? mediaType : context.getResponseMediaType(), response.getHeaders(),\n                    context.getOrCreateOutputStream());\n            context.getOutputStream().close();\n            done = true;\n        } else {\n            interceptors[index++].aroundWriteTo(this);\n            if (!done) {\n                //TODO: how to handle\n                context.setResult(Response.fromResponse(response).replaceAll(headers).build());\n                ServerSerialisers.encodeResponseHeaders(context);","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/jaxrs/WriterInterceptorContextImpl.java#L37-L73","documentation":"RESTEasy Reactive could not find a MessageBodyWriter capable of serializing the response entity for the requested media type. When the initial writer discovery fails (rediscoveryNeeded), the server re-scans registered serializers at write time and throws this InternalServerErrorException (HTTP 500) if none match. This means the runtime has no registered writer for the entity class + media type combination.","triggerScenarios":"Returning a response entity whose class has no registered MessageBodyWriter for the requested @Produces media type; the rediscovery path in ServerSerialisers.findWriters(null, entity.getClass(), mediaType, RuntimeType.SERVER) returns an empty list in WriterInterceptorContextImpl.proceed.","commonSituations":"Returning a POJO without JSON support on the classpath (missing quarkus-rest-jackson/jsonb) with application/json; returning custom types with an @Produces like text/xml when no XML serializer is registered; dynamic media types negotiated to an unsupported format; returning objects from a ResourceMethod without @Produces causing strict writer lookup.","solutions":["Add the appropriate serializer extension, e.g. quarkus-rest-jackson or quarkus-rest-jackson-config / quarkus-resteasy-reactive-jackson for JSON entities","Ensure the resource method's @Produces media type matches a writer available for the entity class (e.g. String handles text/plain)","Register a custom MessageBodyWriter for the entity class via @Provider or ServerMessageBodyWriter","If returning a generic/unknown type, convert it to a supported type (String, byte[], Map) before returning"],"exampleFix":"// before\n@GET\n@Produces(MediaType.APPLICATION_JSON)\npublic MyPojo get() { return new MyPojo(); } // fails if no JSON writer registered\n\n// after (add dependency)\n// <dependency>io.quarkus:quarkus-rest-jackson</dependency>\n@GET\n@Produces(MediaType.APPLICATION_JSON)\npublic MyPojo get() { return new MyPojo(); }","handlingStrategy":"try-catch","validationCode":"// fail fast at build/startup\nassert jakarta.ws.rs.ext.RuntimeDelegate.getInstance() != null;\n// ensure a JSON mapper is on the classpath:\n// Class.forName(\"com.fasterxml.jackson.databind.ObjectMapper\")\nClass<?> jsonMapper = null;\ntry { jsonMapper = Class.forName(\"com.fasterxml.jackson.databind.ObjectMapper\"); } catch (ClassNotFoundException e) { throw new IllegalStateException(\"Add quarkus-rest-jackson to serialize JSON entities\"); }","typeGuard":"boolean hasRegisteredWriter(Class<?> entity, MediaType mt) {\n    return entity == String.class || entity == byte[].class\n        || mt.isCompatible(MediaType.APPLICATION_JSON_TYPE) && jsonExtensionPresent;\n}","tryCatchPattern":"try {\n    return resource.call();\n} catch (InternalServerErrorException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Could not find MessageBodyWriter\")) {\n        log.errorf(\"Entity type %s has no writer; add quarkus-rest-jackson or a custom MessageBodyWriter\", e);\n        return Response.status(500).entity(\"Serialization unsupported\").build();\n    }\n    throw e;\n}","preventionTips":["Always include a JSON extension (quarkus-rest-jackson or quarkus-rest-jsonb) when returning POJOs","Keep @Produces in sync with registered writers for the entity type","Add a startup/integration test that calls each endpoint and asserts 200","Write a custom MessageBodyWriter for any exotic domain types instead of returning raw objects"],"tags":["rest","serialization","http-500","messagebodywriter"],"backgroundTag":"no-message-body-writer-found","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}