{"record":{"id":"b7c2970bbdae5571","repo":"apache/seatunnel","slug":"json-deserialization-exception","errorCode":null,"errorMessage":"Json deserialization exception.","messagePattern":"Json deserialization exception\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/JsonUtils.java","lineNumber":286,"sourceCode":"        return parseObject(text.getBytes(StandardCharsets.UTF_8));\n    }\n\n    public static ObjectNode parseObject(byte[] content) {\n        try {\n            return (ObjectNode) OBJECT_MAPPER.readTree(content);\n        } catch (IOException e) {\n            throw new RuntimeException(\n                    \"String json deserialization exception.\"\n                            + new String(content, StandardCharsets.UTF_8),\n                    e);\n        }\n    }\n\n    public static ArrayNode parseArray(String text) {\n        try {\n            return (ArrayNode) OBJECT_MAPPER.readTree(text);\n        } catch (Exception e) {\n            throw new RuntimeException(\"Json deserialization exception.\", e);\n        }\n    }\n\n    /** json serializer */\n    public static class JsonDataSerializer extends JsonSerializer<String> {\n\n        @Override\n        public void serialize(String value, JsonGenerator gen, SerializerProvider provider)\n                throws IOException {\n            gen.writeRawValue(value);\n        }\n    }\n\n    /** json data deserializer */\n    public static class JsonDataDeserializer extends JsonDeserializer<String> {\n\n        @Override\n        public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/JsonUtils.java#L268-L304","documentation":"JsonUtils.parseArray catches IOException from Jackson readTree — thrown when the text is not valid JSON or cannot be read — and rethrows it as this RuntimeException, so it marks the input as unparsable JSON for array parsing.","triggerScenarios":"Calling JsonUtils.parseArray(text) with malformed JSON, an empty/blank string, or a JSON object/scalar which readTree cannot produce an ArrayNode from (leading to ClassCastException or parse error).","commonSituations":"Consuming third-party list endpoints that sometimes return a single object, reading JSON arrays from files with trailing commas or comments, blank responses from failed requests.","solutions":["Inspect the chained cause and the input string; confirm the text starts with '['","Handle empty input explicitly before calling parseArray","If the source may return an object wrapper, read it as ObjectNode and extract the array field instead","Fix JSON syntax issues (trailing commas, single quotes, comments) in the producer"],"exampleFix":"// before\nArrayNode arr = JsonUtils.parseArray(\"\"); // blank input throws\n// after\nArrayNode arr = text == null || text.isBlank() ? null : JsonUtils.parseArray(text);","handlingStrategy":"type-guard","validationCode":"ArrayNode safeParseArray(String text) {\n    if (text == null || text.isBlank()) return null;\n    try {\n        JsonNode n = JsonUtils.parseObject(text.getBytes(StandardCharsets.UTF_8));\n        return n != null && n.isArray() ? (ArrayNode) n : null;\n    } catch (RuntimeException e) { return null; }\n}","typeGuard":"boolean isArrayPayload(String text) { return text != null && text.trim().startsWith(\"[\"); }","tryCatchPattern":"try {\n    ArrayNode arr = JsonUtils.parseArray(text);\n} catch (RuntimeException e) {\n    log.error(\"invalid array json: {}\", e.getCause());\n    arr = JsonUtils.getNodeFactory().arrayNode();\n}","preventionTips":["Check the first non-whitespace char is '[' before parsing as an array","Handle blank responses explicitly","Fix trailing commas/comments at the producing side, not by regex-repairing at parse time"],"tags":["jackson","deserialization","arraynode"],"backgroundTag":"json-parse-error","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}