{"record":{"id":"57c14574c9f7a31f","repo":"apache/flink","slug":"could-not-serialize-row-s-57c145","errorCode":null,"errorMessage":"Could not serialize row '%s'.","messagePattern":"Could not serialize row '(.+?)'\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/canal/CanalJsonSerializationSchema.java","lineNumber":89,"sourceCode":"                        ignoreNullFields);\n    }\n\n    @Override\n    public void open(InitializationContext context) throws Exception {\n        jsonSerializer.open(context);\n        reuse = new GenericRowData(2);\n    }\n\n    @Override\n    public byte[] serialize(RowData row) {\n        try {\n            StringData opType = rowKind2String(row.getRowKind());\n            ArrayData arrayData = new GenericArrayData(new RowData[] {row});\n            reuse.setField(0, arrayData);\n            reuse.setField(1, opType);\n            return jsonSerializer.serialize(reuse);\n        } catch (Throwable t) {\n            throw new RuntimeException(\"Could not serialize row '\" + row + \"'.\", t);\n        }\n    }\n\n    private StringData rowKind2String(RowKind rowKind) {\n        switch (rowKind) {\n            case INSERT:\n            case UPDATE_AFTER:\n                return OP_INSERT;\n            case UPDATE_BEFORE:\n            case DELETE:\n                return OP_DELETE;\n            default:\n                throw new UnsupportedOperationException(\n                        \"Unsupported operation '\" + rowKind + \"' for row kind.\");\n        }\n    }\n\n    @Override","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/canal/CanalJsonSerializationSchema.java#L71-L107","documentation":"Thrown by CanalJsonSerializationSchema.serialize as a wrapper around any Throwable raised while encoding a RowData into Canal-JSON (it builds a reuse row with the data array and op type, then delegates to the JSON serializer). The cause identifies the real failure — typically the same field-level problems as RowDataToJsonConverters (1415... 1405/1406/1408/1409).","triggerScenarios":"Writing rows with format 'canal-json' to a sink where the inner JSON serialization throws: unsupported column type (RAW), map null keys in FAIL mode, malformed VARIANT values, or a value whose converter fails. Raised per record at runtime.","commonSituations":"Schema drift between the producing pipeline and the canal-json sink table; nullable keys from joins producing map null keys; exotic types in the sink schema; test rows not representative of production data.","solutions":["Read the cause chain of the RuntimeException and fix the underlying converter error (see 1405/1406/1408/1409)","Adjust sink table options ('json.map-null-key.mode'='DROP' or 'LITERAL') or schema (drop RAW columns)","Round-trip test representative rows (nulls, nested maps, variants) through the canal-json serializer before deploying","Quarantine failing records with a dead-letter sink instead of failing the whole job if data quality is the issue"],"exampleFix":"// before: sink schema contains RAW or maps with null keys and default options\n\n// after\nWITH ('connector'='kafka', 'format'='canal-json',\n  'json.map-null-key.mode'='DROP')\n-- and only JSON-compatible column types in the DDL","handlingStrategy":"try-catch","validationCode":"// Smoke-test rows before sinking\ntry { serializer.serialize(sampleRow); } catch (RuntimeException e) { /* fix schema/options before deploy */ }","typeGuard":null,"tryCatchPattern":"catch (RuntimeException e) — unwrap cause; fix the nested converter issue (map null keys, RAW type, variant); quarantine the record rather than failing the job if data-driven.","preventionTips":["Round-trip test representative rows in CI","Set map-null-key policy explicitly for canal-json sinks","Keep only JSON-compatible types in sink schemas"],"tags":["canal","cdc","serialization","runtime"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}