{"record":{"id":"b067e0b34590eec6","repo":"quarkusio/quarkus","slug":"failed-to-serialize-content-of-type","errorCode":null,"errorMessage":"Failed to serialize content of type ","messagePattern":"Failed to serialize content of type ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/EntityPartBuilderImpl.java","lineNumber":162,"sourceCode":"        } else if (content instanceof byte[]) {\n            return new ByteArrayInputStream((byte[]) content);\n        } else if (serialisers != null) {\n            MessageBodyWriter<T> writer = null;\n            List<MessageBodyWriter<?>> writers = serialisers.findWriters(null, rawType, mediaType);\n            for (MessageBodyWriter<?> w : writers) {\n                if (w.isWriteable(rawType, genericType, EMPTY_ANNOTATIONS, mediaType)) {\n                    writer = (MessageBodyWriter<T>) w;\n                    break;\n                }\n            }\n            if (writer != null) {\n                try {\n                    ByteArrayOutputStream baos = new ByteArrayOutputStream();\n                    writer.writeTo(content, rawType, genericType, EMPTY_ANNOTATIONS, mediaType,\n                            new QuarkusMultivaluedHashMap<>(), baos);\n                    return new ByteArrayInputStream(baos.toByteArray());\n                } catch (IOException e) {\n                    throw new IllegalArgumentException(\"Failed to serialize content of type \" + rawType.getName(), e);\n                }\n            } else {\n                return new ByteArrayInputStream(content.toString().getBytes(StandardCharsets.UTF_8));\n            }\n        } else {\n            return new ByteArrayInputStream(content.toString().getBytes(StandardCharsets.UTF_8));\n        }\n    }\n\n    @Override\n    public EntityPart build() throws IllegalStateException, IOException, WebApplicationException {\n        if (content == null) {\n            throw new IllegalStateException(\"No content has been set\");\n        }\n\n        InputStream resolvedContent;\n        if (content instanceof InputStream) {\n            resolvedContent = (InputStream) content;","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/EntityPartBuilderImpl.java#L144-L180","documentation":"During EntityPart.build(), the content is serialized with the matching MessageBodyWriter. If the writer throws an IOException while writing to the internal buffer, the builder wraps it in an IllegalArgumentException reading 'Failed to serialize content of type <rawType.getName()>'. This indicates the registered writer for the part's media type failed to produce bytes for the given object.","triggerScenarios":"Calling build() on an EntityPart whose content object's MessageBodyWriter throws IOException — e.g. a custom writer writing through a stream that fails, or Jackson/JSON-B choking mid-serialization on the part object with the declared media type (application/json etc.).","commonSituations":"Serializing a POJO whose getter throws or whose nested Jackson serialization fails (unwrapped streams, invalid @JsonValue), custom MessageBodyWriter implementations with I/O bugs, or a media type registered that has no reliable writer for the object.","solutions":["Inspect the wrapped IOException cause (e.getCause()) to find the underlying writer failure and fix the object or writer.","Verify the media type set on the part matches a writer that fully supports the content type (e.g. application/json with JSON-B/Jackson registered).","Simplify the part content: serialize the object to String/byte[] yourself first, then pass that as content.","If a custom MessageBodyWriter is involved, fix its writeTo to not throw raw IOException for logical errors."],"exampleFix":"// before\nEntityPart part = EntityPart.withName(\"payload\")\n        .content(myUnserializableObject)\n        .mediaType(\"application/json\")\n        .build(); // throws IllegalArgumentException wrapping IOException\n// after\nString json = JsonbBuilder.create().toJson(safeDto);\nEntityPart part = EntityPart.withName(\"payload\")\n        .content(json, new GenericType<String>() {})\n        .mediaType(\"application/json\")\n        .build();","handlingStrategy":"try-catch","validationCode":"// Pre-serialize to verify the object can be converted\nbyte[] probe = content.toString().getBytes(StandardCharsets.UTF_8); // fallback path sanity","typeGuard":null,"tryCatchPattern":"try {\n    EntityPart part = builder.build();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Failed to serialize content of type\")) {\n        LOG.errorf(e.getCause(), \"EntityPart serialization failed; cause: %s\", e.getCause());\n        // re-serialize as String or fix writer\n    }\n    throw e;\n}","preventionTips":["Always inspect getCause() — the real failure is the wrapped IOException.","Test part serialization of your DTOs in unit tests before shipping.","Prefer simple part content types (String, byte[]) for non-standard objects."],"tags":["resteasy-reactive","multipart","serialization","messagebodywriter","jax-rs"],"backgroundTag":"serialization-failed","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"}