{"record":{"id":"b1a1bb0fd9c1d30e","repo":"apache/flink","slug":"fail-to-serialize-at-field-s-b1a1bb","errorCode":null,"errorMessage":"Fail to serialize at field: %s.","messagePattern":"Fail to serialize at field: (.+?)\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/RowDataToJsonConverters.java","lineNumber":362,"sourceCode":"            ObjectNode node;\n            // reuse could be a NullNode if last record is null.\n            if (reuse == null || reuse.isNull()) {\n                node = mapper.createObjectNode();\n            } else {\n                node = (ObjectNode) reuse;\n            }\n            RowData row = (RowData) value;\n            for (int i = 0; i < fieldCount; i++) {\n                String fieldName = fieldNames[i];\n                try {\n                    Object field = fieldGetters[i].getFieldOrNull(row);\n                    if (field != null || !ignoreNullFields) {\n                        node.set(\n                                fieldName,\n                                fieldConverters[i].convert(mapper, node.get(fieldName), field));\n                    }\n                } catch (Throwable t) {\n                    throw new RuntimeException(\n                            String.format(\"Fail to serialize at field: %s.\", fieldName), t);\n                }\n            }\n            return node;\n        };\n    }\n\n    private RowDataToJsonConverter wrapIntoNullableConverter(RowDataToJsonConverter converter) {\n        return (mapper, reuse, object) -> {\n            if (object == null) {\n                return mapper.getNodeFactory().nullNode();\n            }\n\n            return converter.convert(mapper, reuse, object);\n        };\n    }\n}\n","sourceCodeStart":344,"sourceCodeEnd":380,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/RowDataToJsonConverters.java#L344-L380","documentation":"Thrown by the ROW converter in RowDataToJsonConverters when any per-field serializer throws while writing one field of a row to JSON. It is a wrapper: the message names the field and the cause holds the real failure (unsupported type, bad value for the target JSON node, variant failure, etc.). Diagnose the cause chain for the named field.","triggerScenarios":"Any field-level serialization error: a VARIANT value failing convertVariant (1406), a map with null keys inside a nested row (1408), an unsupported type nested in a ROW, or a value whose conversion throws. Raised at runtime on the offending record during JSON sink writes.","commonSituations":"Schema drift between computing pipeline and sink schema; nested maps with null keys from joins/aggregations; RAW or exotic types nested inside ROW columns written to JSON.","solutions":["Inspect the cause of the RuntimeException to find the real converter failure for the named field","Fix the specific nested cause: adjust types, set 'json.map-null-key.mode', remove RAW columns, or sanitize values before the sink","Test the sink schema with a representative sample of rows (including edge cases: nulls, empty maps, variants) before production","Add a dead-letter/quarantine path for records that legitimately cannot be serialized"],"exampleFix":"// before: nested map with null key hits JSON sink\nINSERT INTO kafka_sink SELECT * FROM agg_view;\n\n// after: sanitize before sinking\nINSERT INTO kafka_sink SELECT id, MAP_VALUES(...) /* or COALESCE keys */ FROM agg_view;","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"catch (RuntimeException e) — extract field name from message, unwrap cause, apply the nested fix (map-null-key mode, type change, variant quarantine); do not retry blindly.","preventionTips":["Round-trip test representative rows through the JSON serializer","Keep computing schema and sink schema in sync","Route unserializable records to a dead-letter topic"],"tags":["json","row","field-conversion","serialization","runtime"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}