{"record":{"id":"57cf5b2255bc063a","repo":"quarkusio/quarkus","slug":"could-not-find-messagebodywriter-for-entityclass-57cf5b","errorCode":null,"errorMessage":"Could not find MessageBodyWriter for ${entityClass} 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/multipart/MultipartMessageBodyWriter.java","lineNumber":303,"sourceCode":"        MessageBodyWriter<Object>[] writers = (MessageBodyWriter<Object>[]) serializers\n                .findWriters(null, entityClass, mediaType, RuntimeType.SERVER)\n                .toArray(ServerSerialisers.NO_WRITER);\n        boolean wrote = false;\n        for (MessageBodyWriter<Object> writer : writers) {\n            if (writer.isWriteable(entityClass, entityType, Serialisers.NO_ANNOTATION, mediaType)) {\n                try (NoopCloseAndFlushOutputStream writerOutput = new NoopCloseAndFlushOutputStream(os)) {\n                    // FIXME: spec doesn't really say what headers we should use here\n                    writer.writeTo(entity, entityClass, entityType, Serialisers.NO_ANNOTATION, mediaType,\n                            new QuarkusMultivaluedHashMap<>(), writerOutput);\n                    wrote = true;\n                }\n\n                break;\n            }\n        }\n\n        if (!wrote) {\n            throw new IllegalStateException(\"Could not find MessageBodyWriter for \" + entityClass + \" as \" + mediaType);\n        }\n    }\n\n    private String generateBoundary() {\n        return UUID.randomUUID().toString();\n    }\n\n    private void appendBoundaryIntoMediaType(ResteasyReactiveRequestContext requestContext, String boundary,\n            MediaType mediaType) {\n        MediaType mediaTypeWithBoundary = new MediaType(mediaType.getType(), mediaType.getSubtype(),\n                Collections.singletonMap(BOUNDARY_PARAM, boundary));\n        requestContext.setResponseContentType(mediaTypeWithBoundary);\n\n        // this is a total hack, but it's needed to make RestResponse<MultipartFormDataOutput> work properly\n        requestContext.serverResponse().setResponseHeader(CONTENT_TYPE, mediaTypeWithBoundary.toString());\n        if (requestContext.getResponse().isCreated()) {\n            requestContext.getResponse().get().getHeaders().remove(CONTENT_TYPE);\n        }","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/multipart/MultipartMessageBodyWriter.java#L285-L321","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\npublic class Output { public MyPojo part; } // no writer for MyPojo as text/plain\n// after\npublic class Output {\n    @PartType(MediaType.APPLICATION_JSON)\n    public MyPojo part;\n}","handlingStrategy":"validation","validationCode":"for (Field f : output.getClass().getDeclaredFields()) { PartType pt = f.getAnnotation(PartType.class); if (pt == null) throw new ConfigurationException(\"missing @PartType on \" + f.getName()); }","typeGuard":null,"tryCatchPattern":"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; }","preventionTips":["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"],"tags":["rest","multipart","serialization"],"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"}