apache/seatunnel · error · RuntimeException
Failed to convert row to JSON
Error message
Failed to convert row to JSON
What it means
convertRowToJson serializes a SeaTunnelRow into a JSON string (used for JSON-based writes). Any exception during field mapping or Jackson serialization is rethrown as a RuntimeException with this message, chaining the original cause. It signals a row that cannot be represented as the expected JSON document.
Source
Thrown at seatunnel-connectors-v2/connector-databend/src/main/java/org/apache/seatunnel/connectors/seatunnel/databend/sink/DatabendSinkWriter.java:523
jsonNode.put(fieldName, (Double) value);
} else if (value instanceof Boolean) {
jsonNode.put(fieldName, (Boolean) value);
} else if (value instanceof BigDecimal) {
jsonNode.put(fieldName, (BigDecimal) value);
} else if (value instanceof java.sql.Timestamp) {
jsonNode.put(fieldName, value.toString());
} else if (value instanceof java.sql.Date) {
jsonNode.put(fieldName, value.toString());
} else if (value instanceof byte[]) {
jsonNode.put(fieldName, Base64.getEncoder().encodeToString((byte[]) value));
} else {
jsonNode.put(fieldName, value.toString());
}
}
return objectMapper.writeValueAsString(jsonNode);
} catch (Exception e) {
throw new RuntimeException("Failed to convert row to JSON", e);
}
}
private void initializePreparedStatement(SeaTunnelRow row) throws SQLException {
log.info("Initializing PreparedStatement based on row data");
// use sinkTablePath to get Schema
String database = sinkTablePath.getDatabaseName();
String table = sinkTablePath.getTableName();
log.info("Querying target table schema for {}.{}", database, table);
SeaTunnelRowType actualTableSchema = queryTableSchema(database, table);
if (actualTableSchema != null) {
log.info("Using actual table schema: {}", actualTableSchema);
this.insertSql = generateInsertSql(database, table, actualTableSchema);
} else {
log.warn("Could not query table schema, using inferred schema from data");View on GitHub (pinned to cf67b549a7)
Solutions
- Read the chained cause ('Caused by') to see the exact serialization failure.
- Check for unsupported SeaTunnel types in the row and map them to JSON-compatible types with an upstream transform.
- Verify the catalog table metadata is loaded correctly so field names align with row fields.
- Cast/normalize special columns (binary, complex types) before the Databend sink.
Example fix
// before: raw binary field reaches JSON conversion row.setField(2, bytes); // after: encode binary before sinking row.setField(2, Base64.getEncoder().encodeToString(bytes));
Defensive patterns
Strategy: type-guard
Validate before calling
// ensure every field is JSON-safe before sinking
for (int i = 0; i < row.getArity(); i++) {
Object v = row.getField(i);
if (v instanceof byte[] || v instanceof Map || v instanceof List) {
// normalize before write
}
} Type guard
boolean isJsonSerializable(Object v) {
return v == null || v instanceof String || v instanceof Number
|| v instanceof Boolean || v instanceof java.time.temporal.Temporal;
} Try / catch
try {
writer.write(row);
} catch (RuntimeException e) {
if ("Failed to convert row to JSON".equals(e.getMessage())) {
log.error("JSON conversion failed; offending row types: "
+ Arrays.toString(row.getRowType().getFieldTypes()), e.getCause());
} else throw e;
} Prevention
- Encode binary/special types as strings upstream
- Keep row schema in sync with catalog metadata
- Test serialization with representative production rows
- Pin a compatible Jackson version in the deployment
When it happens
Trigger: objectMapper.writeValueAsString throws (unsupported value types, Jackson config issue), or row fields contain objects that fail toString/field mapping; also triggered when the row shape does not match the expected catalog metadata during field iteration.
Common situations: Binary/special types (e.g. byte arrays, nested arrays) that Jackson cannot map by default; schema drift so row fields no longer match declared catalog columns; null catalog metadata causing wrong field-name lookups; corrupt values from upstream CDC sources.
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/a6f93ba9cfa773c9.
Report an issue: GitHub.