{"record":{"id":"5d97bcf0e2bbc448","repo":"apache/seatunnel","slug":"serialization-error","errorCode":"SERIALIZATION_ERROR","errorMessage":"Serialization error on record : ${element}","messagePattern":"Serialization error on record : (.+?)","errorType":"error_code","errorClass":"SeaTunnelAvroFormatException","httpStatus":null,"severity":"error","filePath":"seatunnel-formats/seatunnel-format-avro/src/main/java/org/apache/seatunnel/format/avro/AvroSerializationSchema.java","lineNumber":59,"sourceCode":"    private final RowToAvroConverter converter;\n    private final DatumWriter<GenericRecord> writer;\n\n    public AvroSerializationSchema(SeaTunnelRowType rowType) {\n        this.out = new ByteArrayOutputStream();\n        this.encoder = EncoderFactory.get().binaryEncoder(out, null);\n        this.converter = new RowToAvroConverter(rowType);\n        this.writer = this.converter.getWriter();\n    }\n\n    @Override\n    public byte[] serialize(SeaTunnelRow element) {\n        GenericRecord record = converter.convertRowToGenericRecord(element);\n        try {\n            writer.write(record, encoder);\n            encoder.flush();\n            return out.toByteArray();\n        } catch (IOException e) {\n            throw new SeaTunnelAvroFormatException(\n                    AvroFormatErrorCode.SERIALIZATION_ERROR,\n                    \"Serialization error on record : \" + element);\n        } finally {\n            out.reset();\n        }\n    }\n}\n","sourceCodeStart":41,"sourceCodeEnd":67,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-formats/seatunnel-format-avro/src/main/java/org/apache/seatunnel/format/avro/AvroSerializationSchema.java#L41-L67","documentation":"SeaTunnelAvroFormatException with code SERIALIZATION_ERROR thrown by AvroSerializationSchema.serialize when the Avro writer fails to encode a converted GenericRecord with an IOException. The RowConverter has already produced the GenericRecord; the failure occurs at the encoder/writer level (schema mismatch, I/O on the output stream).","triggerScenarios":"Calling serialize(SeaTunnelRow) where writer.write(record, encoder) or encoder.flush() throws IOException — typically a record not matching the Avro schema (wrong field type/null in non-nullable field).","commonSituations":"Row schema changed after the Avro schema was created; null values in fields the schema marks non-nullable; numeric type mismatches after a connector change; downstream reuse of a closed/reset stream.","solutions":["Compare the SeaTunnelRowType against the Avro schema and make fields nullable (union with NULL) where nulls occur","Regenerate the schema from the current row type so they match","Log/print the failing record to identify the offending field","Catch SeaTunnelAvroFormatException and route bad records to a dead-letter path"],"exampleFix":"// before\nSchema schema = SchemaBuilder.builder().stringType(); // non-nullable field\nrow.setField(0, null);\n// after\nSchema schema = SchemaBuilder.builder().nullable().stringType();\nrow.setField(0, null); // now valid","handlingStrategy":"try-catch","validationCode":"// pre-validate nulls against the schema\nrowType.getFieldTypes().forEach((i, t) -> {\n    if (row.getField(i) == null && !isNullable(schema, i))\n        throw new IllegalArgumentException(\"null in non-nullable field \" + i);\n});","typeGuard":null,"tryCatchPattern":"try {\n    byte[] bytes = avroSerializationSchema.serialize(row);\n} catch (SeaTunnelAvroFormatException e) {\n    LOG.error(\"Avro serialization failed, code={}\", e.getFormatErrorCode(), e);\n    deadLetterSink.send(row); // don't crash the pipeline\n}","preventionTips":["Always generate the Avro schema from the exact SeaTunnelRowType in use","Mark optional fields nullable (union with NULL) in the schema","Keep row type and schema in sync when schemas evolve","Log the failing record for triage"],"tags":["java","avro","serialization","format"],"backgroundTag":"json-marshal-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}