apache/seatunnel · error · RuntimeException

Fail to serialize at field: ${fieldName}.

Error message

Fail to serialize at field: ${fieldName}.

What it means

The row converter wraps per-field Avro conversion in a try/catch and rethrows as a RuntimeException annotated with the failing field name, so users know which schema field caused serialization to fail; the original cause is chained.

Source

Thrown at seatunnel-connectors-v2/connector-hudi/src/main/java/org/apache/seatunnel/connectors/seatunnel/hudi/sink/convert/RowDataToAvroConverters.java:257

                        .toArray(RowDataToAvroConverter[]::new);
        final SeaTunnelDataType<?>[] fieldTypes = rowType.getFieldTypes();

        return new RowDataToAvroConverter() {
            private static final long serialVersionUID = 1L;

            @Override
            public Object convert(Schema schema, Object object) {
                final SeaTunnelRow row = (SeaTunnelRow) object;
                final List<Schema.Field> fields = schema.getFields();
                final GenericRecord record = new GenericData.Record(schema);
                for (int i = 0; i < fieldTypes.length; ++i) {
                    final Schema.Field schemaField = fields.get(i);
                    try {
                        Object avroObject =
                                fieldConverters[i].convert(schemaField.schema(), row.getField(i));
                        record.put(i, avroObject);
                    } catch (Throwable t) {
                        throw new RuntimeException(
                                String.format(
                                        "Fail to serialize at field: %s.", schemaField.name()),
                                t);
                    }
                }
                return record;
            }
        };
    }

    private static RowDataToAvroConverter createArrayConverter(ArrayType<?, ?> arrayType) {
        final RowDataToAvroConverter elementConverter = createConverter(arrayType.getElementType());

        return new RowDataToAvroConverter() {
            private static final long serialVersionUID = 1L;

            @Override
            public Object convert(Schema schema, Object object) {

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Inspect the chained cause ('Caused by') to find the root type/encoding problem and fix the data or schema
  2. Align the SeaTunnel source schema with the Hudi table Avro schema (types must match field-by-field)
  3. Cast offending columns upstream with a SQL transform to the expected type
  4. Refresh stale Hudi table schema configuration after schema evolution

Example fix

// before: field 'age' declared STRING in source, INT in Avro schema
// after: CAST(age AS INT) in upstream SQL transform
Defensive patterns

Strategy: try-catch

Try / catch

try {
    sink.write(row);
} catch (RuntimeException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("Fail to serialize at field:")) {
        String field = e.getMessage().replace("Fail to serialize at field: ", "").replace(".", "");
        LOG.error("Check value/type of field {} against the Hudi Avro schema; cause: {}", field, e.getCause());
    } else { throw e; }
}

Prevention

When it happens

Trigger: During convert() of a SeaTunnelRow to an Avro record, fieldConverters[i].convert() throws for field i (value not matching the Avro schema, e.g. wrong type, out-of-domain value, null in non-nullable field).

Common situations: Source row value types diverging from declared SeaTunnel schema; Hudi Avro schema evolved while data uses old types; character/date conversion failures on malformed values.

Understand the failure class

Background: "JSON serialization failed", "not JSON serializable", "Failed to serialize": why JSON marshaling errors happen and how to fix them — this error's family across 46 libraries.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/3cbbc3057be64bbe. Report an issue: GitHub.