{"record":{"id":"50a28dead13a2455","repo":"apache/seatunnel","slug":"failed-to-serialize-event-as-json-50a28d","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/LineOutputFormatter.java","lineNumber":62,"sourceCode":"                ObjectNode node = buildLineObject(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(buildLineObject(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 buildLineObject(\n            int index, MultilineAssembler.LineElement line, String payloadText) {\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        node.put(\"payload\", payloadText);\n        return node;\n    }\n}\n","sourceCodeStart":44,"sourceCodeEnd":78,"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/LineOutputFormatter.java#L44-L78","documentation":"LineOutputFormatter wraps Jackson JsonProcessingException in an IllegalStateException reporting that the event could not be serialized as JSON. It signals an internal serialization failure while writing the ObjectNode tree to a string.","triggerScenarios":"Jackson throws JsonProcessingException inside format(), e.g. an unserializable value inserted into the ObjectNode or a writer-level failure.","commonSituations":"Unserializable or malformed payload content placed into the tree by buildLineObject; ObjectMapper misconfiguration; corrupted line data from a source file.","solutions":["Read the wrapped cause from the IllegalStateException to identify the Jackson error","Sanitize/validate line payload text before inserting it into the ObjectNode","Catch JsonProcessingException-based failures and fall back to emitting the raw line","Verify ObjectMapper setup (modules, features) matches the expected output format"],"exampleFix":"// before\nString json = lineFormatter.format(event, sourceId);\n// after\ntry {\n    String json = lineFormatter.format(event, sourceId);\n} catch (IllegalStateException e) {\n    LOG.warn(\"Falling back to raw line for source {}: {}\", sourceId, e.getCause());\n}","handlingStrategy":"try-catch","validationCode":"// validate payload text is well-formed before formatting\nObjects.requireNonNull(payloadText, \"payloadText\");","typeGuard":null,"tryCatchPattern":"try {\n    lineFormatter.format(event, sourceId);\n} catch (IllegalStateException e) {\n    LOG.warn(\"Serialization failed, using raw line: {}\", e.getCause());\n}","preventionTips":["Sanitize line content before inserting into JSON nodes","Fall back to raw text output when serialization fails","Keep the Jackson version consistent with shaded dependencies"],"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"}