{"record":{"id":"b7705c622e1cc9bc","repo":"quarkusio/quarkus","slug":"could-not-find-messagebodywriter-for-entityclass-b7705c","errorCode":null,"errorMessage":"Could not find MessageBodyWriter for ${entityClass} / ${entityType} as ${mediaType}","messagePattern":"Could not find MessageBodyWriter for (.+?) / (.+?) as (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/StreamingUtil.java","lineNumber":82,"sourceCode":"        MediaType mediaType = context.getResponseMediaType();\n        // FIXME: this should belong somewhere else as it's generic\n        @SuppressWarnings(\"unchecked\")\n        MessageBodyWriter<Object>[] writers = (MessageBodyWriter<Object>[]) serialisers\n                .findWriters(null, entityClass, mediaType, RuntimeType.SERVER)\n                .toArray(ServerSerialisers.NO_WRITER);\n        StreamingOutputStream baos = new StreamingOutputStream();\n        boolean wrote = false;\n        for (MessageBodyWriter<Object> writer : writers) {\n            if (writer.isWriteable(entityClass, entityType, context.getAllAnnotations(), mediaType)) {\n                // FIXME: spec doesn't really say what headers we should use here\n                writer.writeTo(entity, entityClass, entityType, context.getAllAnnotations(), mediaType,\n                        new QuarkusMultivaluedHashMap<>(), baos);\n                wrote = true;\n                break;\n            }\n        }\n        if (!wrote) {\n            throw new IllegalStateException(\n                    \"Could not find MessageBodyWriter for \" + entityClass + \" / \" + entityType + \" as \" + mediaType);\n        }\n        return baos.toByteArray();\n    }\n\n    public static void setHeaders(ResteasyReactiveRequestContext context, ServerHttpResponse response,\n            List<PublisherResponseHandler.StreamingResponseCustomizer> customizers) {\n        // FIXME: spec says we should flush the headers when first message is sent or when the resource method returns, whichever\n        // happens first\n        if (!response.headWritten()) {\n            response.setStatusCode(Response.Status.OK.getStatusCode());\n            response.setResponseHeader(HttpHeaders.CONTENT_TYPE, context.getResponseContentType().toString());\n            response.setChunked(true);\n            for (int i = 0; i < customizers.size(); i++) {\n                customizers.get(i).customize(response);\n            }\n        }\n    }","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/StreamingUtil.java#L64-L100","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\n@GET @Produces(MediaType.APPLICATION_XML)\npublic MyPojo get() { return new MyPojo(); } // no XML writer\n// after\n@GET @Produces(MediaType.APPLICATION_JSON)\npublic MyPojo get() { return new MyPojo(); } // with quarkus-resteasy-reactive-jackson on classpath","handlingStrategy":"validation","validationCode":"if (!produces.contains(MediaType.APPLICATION_JSON)) { throw new ConfigurationException(\"No MessageBodyWriter for \" + entity.getClass() + \" with \" + produces); }","typeGuard":null,"tryCatchPattern":"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; }","preventionTips":["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"],"tags":["rest","serialization","resteasy-reactive"],"backgroundTag":"no-messagebodywriter-for-media-type","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"}