{"record":{"id":"fd7c8a86ef42a52c","repo":"apache/dolphinscheduler","slug":"json-deserialization-exception","errorCode":null,"errorMessage":"Json deserialization exception.","messagePattern":"Json deserialization exception\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java","lineNumber":353,"sourceCode":"    }\n\n    public static ObjectNode parseObject(String text) {\n        try {\n            if (StringUtils.isEmpty(text)) {\n                return parseObject(text, ObjectNode.class);\n            } else {\n                return (ObjectNode) objectMapper.readTree(text);\n            }\n        } catch (Exception e) {\n            throw new RuntimeException(\"String json deserialization exception.\", e);\n        }\n    }\n\n    public static ArrayNode parseArray(String text) {\n        try {\n            return (ArrayNode) objectMapper.readTree(text);\n        } catch (Exception e) {\n            throw new RuntimeException(\"Json deserialization exception.\", e);\n        }\n    }\n\n    /**\n     * json serializer\n     */\n    public static class JsonDataSerializer extends JsonSerializer<String> {\n\n        @Override\n        public void serialize(String value, JsonGenerator gen, SerializerProvider provider) throws IOException {\n            gen.writeRawValue(value);\n        }\n\n    }\n\n    public static class JsonDataDeserializer extends JsonDeserializer<String> {\n\n        @Override","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java#L335-L371","documentation":"JSONUtils.parseArray(String) parses a JSON string into an ArrayNode by delegating to objectMapper.readTree and casting. Any parsing failure is wrapped in a RuntimeException with this message. It fails both when the text is invalid JSON and when the parsed tree is not an array (ClassCastException from the cast).","triggerScenarios":"Calling JSONUtils.parseArray(text) where text is malformed JSON, or where text is valid JSON but not an array (e.g. an object '{...}', a bare string, or a number), causing readTree to succeed but the (ArrayNode) cast to fail.","commonSituations":"An API or config value that changed shape across versions from array to object; passing a JSON object where a list was expected; empty or whitespace-only string produced by a failed upstream call.","solutions":["Check the input string: it must start with '[' and be well-formed JSON","Verify the upstream schema — if the value may be an object, parse with parseObject and read the array field from it","Catch the RuntimeException and return Collections.emptyList() when the input is optional/blank","Validate the payload shape with readTree + isArray before casting","Fix the producer so it emits a JSON array"],"exampleFix":"// before\nArrayNode nodes = JSONUtils.parseArray(configJson);\n// after\nArrayNode nodes = configJson != null && configJson.trim().startsWith(\"[\")\n    ? JSONUtils.parseArray(configJson)\n    : JsonNodeFactory.instance.arrayNode();","handlingStrategy":"validation","validationCode":"boolean isValidJsonArray(String s) {\n  if (s == null || !s.trim().startsWith(\"[\")) return false;\n  try { return JSONUtils.parseArray(s).isArray(); } catch (Exception e) { return false; }\n}","typeGuard":"ArrayNode safeParseArray(String s) {\n  if (s == null || !s.trim().startsWith(\"[\")) return JsonNodeFactory.instance.arrayNode();\n  try { return JSONUtils.parseArray(s); } catch (Exception e) { return JsonNodeFactory.instance.arrayNode(); }\n}","tryCatchPattern":"try {\n  ArrayNode arr = JSONUtils.parseArray(text);\n} catch (RuntimeException e) {\n  log.warn(\"Expected a JSON array but got: {}\", text, e);\n  arr = JsonNodeFactory.instance.arrayNode();\n}","preventionTips":["Confirm the payload shape (array vs object) against the producer's schema","Guard with a startsWith(\"[\") check when the shape is not guaranteed","Handle schema drift between service versions explicitly","Return empty collections instead of crashing when the field is optional"],"tags":["json","deserialization","parsing","jackson"],"backgroundTag":"json-parse-error","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}