{"record":{"id":"3d6d1de0eaaf96b8","repo":"apache/dolphinscheduler","slug":"string-json-deserialization-exception","errorCode":null,"errorMessage":"String json deserialization exception.","messagePattern":"String 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":345,"sourceCode":"            return null;\n        }\n        try {\n            return toJsonString(obj).getBytes(UTF_8);\n        } catch (Exception e) {\n            throw new IllegalArgumentException(\"Object: \" + obj + \" to json serialization exception.\", e);\n        }\n\n    }\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 {","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java#L327-L363","documentation":"JSONUtils.parseObject(String) parses a JSON string into an ObjectNode. If the text is non-empty but not valid JSON (or readTree otherwise fails), it wraps the exception in a RuntimeException with this generic message. Empty strings are delegated to parseObject(text, ObjectNode.class) and do not reach this throw site.","triggerScenarios":"Calling JSONUtils.parseObject(text) with malformed JSON, truncated JSON, or a JSON value that readTree cannot parse (e.g. invalid escape sequences, trailing garbage).","commonSituations":"Reading a JSON config file or task parameter that was hand-edited; decoding a response body from an external service that returned HTML or an error page instead of JSON; string truncated by a length limit or encoding mismatch.","solutions":["Log/print the input string and validate it with a JSON linter to find the syntax error","If the source is an HTTP endpoint, check the response content-type and body before parsing (it may be an HTML error page)","Ensure the string is not truncated or double-escaped (e.g. \\\" inside JSON stored in another JSON)","Use the tryParseObject/safe variant or catch the RuntimeException and fall back to a default ObjectNode","Fix the producer of the JSON to emit valid UTF-8 JSON"],"exampleFix":"// before\nObjectNode node = JSONUtils.parseObject(responseBody);\n// after\nObjectNode node = StringUtils.isNotBlank(responseBody) && responseBody.trim().startsWith(\"{\")\n    ? JSONUtils.parseObject(responseBody)\n    : JsonNodeFactory.instance.objectNode();","handlingStrategy":"try-catch","validationCode":"boolean isValidJsonObject(String s) {\n  if (s == null || s.trim().isEmpty()) return false;\n  try { return JSONUtils.parseObject(s).isObject(); } catch (Exception e) { return false; }\n}","typeGuard":"ObjectNode safeParseObject(String s) {\n  try { return JSONUtils.parseObject(s); } catch (Exception e) { return JsonNodeFactory.instance.objectNode(); }\n}","tryCatchPattern":"try {\n  ObjectNode node = JSONUtils.parseObject(text);\n} catch (RuntimeException e) {\n  log.warn(\"Invalid JSON input: {}\", text, e);\n  node = JsonNodeFactory.instance.objectNode(); // or rethrow with context\n}","preventionTips":["Validate/lint JSON config files before deployment","Check HTTP content-type is application/json before parsing response bodies","Prefer JSONUtils.parseObject(text, Class) variants that handle empty input","Log the offending string (truncated) when wrapping parse failures"],"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"}