{"record":{"id":"5c494bac4017750d","repo":"apache/seatunnel","slug":"failed-to-serialize-event-as-json","errorCode":null,"errorMessage":"failed to serialize event as JSON","messagePattern":"failed to serialize event as JSON","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"seatunnel-edge-agent/seatunnel-edge-agent-connector/src/main/java/org/apache/seatunnel/edge/agent/connector/file/output/JsonOutputFormatter.java","lineNumber":63,"sourceCode":"                ObjectNode node = buildLineObjectWithParsedPayload(0, first, first.getText());\n                json = objectMapper.writeValueAsString(node);\n            } else {\n                ArrayNode array = objectMapper.createArrayNode();\n                for (int i = 0; i < event.size(); i++) {\n                    MultilineAssembler.LineElement e = event.get(i);\n                    array.add(buildLineObjectWithParsedPayload(i, e, e.getText()));\n                }\n                json = objectMapper.writeValueAsString(array);\n            }\n            return new CollectedRecord(\n                    json,\n                    sourceId,\n                    first.getFilePath(),\n                    last.getOffset(),\n                    first.getLineNumber(),\n                    first.getTs());\n        } catch (JsonProcessingException e) {\n            throw new IllegalStateException(\"failed to serialize event as JSON\", e);\n        }\n    }\n\n    private ObjectNode buildLineObjectWithParsedPayload(\n            int index, MultilineAssembler.LineElement line, String lineText) {\n        ObjectNode node = objectMapper.createObjectNode();\n        node.put(\"_index\", index);\n        node.put(\"_file\", line.getFilePath());\n        node.put(\"_line\", line.getLineNumber());\n        node.put(\"_offset\", line.getOffset());\n        node.put(\"_ts\", line.getTs());\n        putPayload(node, lineText);\n        return node;\n    }\n\n    private void putPayload(ObjectNode node, String lineText) {\n        try {\n            JsonNode parsed = objectMapper.readTree(lineText);","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-edge-agent/seatunnel-edge-agent-connector/src/main/java/org/apache/seatunnel/edge/agent/connector/file/output/JsonOutputFormatter.java#L45-L81","documentation":"After building the JSON representation of the event, the formatter wraps any Jackson JsonProcessingException in an IllegalStateException indicating JSON serialization failed. This is an internal serialization failure: the ObjectNode tree Jackson built could not be written out as a string.","triggerScenarios":"Jackson throws JsonProcessingException inside format() — e.g. a broken ObjectNode configuration, an unsupported value type inserted into the tree, or an I/O-backed writer failure.","commonSituations":"Custom ObjectNode extensions or exotic value types added via buildLineObjectWithParsedPayload; a misconfigured ObjectMapper module; extremely large payloads hitting writer limits.","solutions":["Inspect the wrapped cause (e.getCause()) to find the actual Jackson failure","Ensure all values inserted into the ObjectNode are Jackson-serializable types","Catch JsonProcessingException upstream and fall back to plain-text line output","Check for circular or oversized payload data in parsed line content"],"exampleFix":"// before\nString json = formatter.format(event, sourceId);\n// after\ntry {\n    String json = formatter.format(event, sourceId);\n} catch (IllegalStateException e) {\n    LOG.error(\"JSON serialization failed for source {}: {}\", sourceId, e.getCause());\n}","handlingStrategy":"try-catch","validationCode":"// ensure payload values are plain strings/numbers before inserting into ObjectNode\nObjects.requireNonNull(lineText, \"lineText\");","typeGuard":null,"tryCatchPattern":"try {\n    formatter.format(event, sourceId);\n} catch (IllegalStateException e) {\n    LOG.error(\"JSON serialization failed: {}\", e.getCause());\n}","preventionTips":["Only insert Jackson-serializable values into ObjectNodes","Keep the ObjectMapper configuration simple and shared","Log e.getCause() to surface the underlying JsonProcessingException"],"tags":["java","jackson","serialization"],"backgroundTag":"json-serialization-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}