{"record":{"id":"cb3f64a39f84e07d","repo":"apache/seatunnel","slug":"json-to-map-exception","errorCode":null,"errorMessage":"json to map exception!","messagePattern":"json to map exception!","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/JsonUtils.java","lineNumber":229,"sourceCode":"    /**\n     * json to map\n     *\n     * @param json json\n     * @param classK classK\n     * @param classV classV\n     * @param <K> K\n     * @param <V> V\n     * @return to map\n     */\n    public static <K, V> Map<K, V> toMap(String json, Class<K> classK, Class<V> classV) {\n        if (StringUtils.isEmpty(json)) {\n            return Collections.emptyMap();\n        }\n\n        try {\n            return OBJECT_MAPPER.readValue(json, new TypeReference<Map<K, V>>() {});\n        } catch (Exception e) {\n            throw new RuntimeException(\"json to map exception!\", e);\n        }\n    }\n\n    /**\n     * json to object\n     *\n     * @param json json string\n     * @param type type reference\n     * @param <T> type\n     * @return return parse object\n     */\n    public static <T> T parseObject(String json, TypeReference<T> type) {\n        if (StringUtils.isEmpty(json)) {\n            return null;\n        }\n\n        try {\n            return OBJECT_MAPPER.readValue(json, type);","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/JsonUtils.java#L211-L247","documentation":"JsonUtils.toMap wraps any Jackson failure (invalid JSON, JSON that is not an object, or key/value types not matching the requested K/V classes) into this RuntimeException, signaling the json string could not be deserialized into a Map.","triggerScenarios":"Calling JsonUtils.toMap(json) with invalid JSON, a JSON array or scalar instead of an object, or values that don't fit the K/V generic types (e.g. numbers when Map<String,String> expected).","commonSituations":"Parsing config snippets or webhook payloads, reading JSON written by another tool with different types, generic-type erasure surprises when K/V don't match actual JSON types.","solutions":["Read the chained cause: JsonParseException = invalid JSON; MismatchedInputException = shape/type mismatch","Ensure the input is a JSON object starting with '{'","Adjust generic types so V matches the actual JSON value types (e.g. Map<String,Object> for mixed values)","Validate the JSON string externally (jq / an online parser) before calling"],"exampleFix":"// before\nMap<String, String> m = JsonUtils.toMap(mixedJson); // values contain numbers/objects\n// after\nMap<String, Object> m = JsonUtils.toMap(mixedJson);","handlingStrategy":"validation","validationCode":"boolean isJsonObject(String s) { return s != null && s.trim().startsWith(\"{\"); }","typeGuard":null,"tryCatchPattern":"try {\n    Map<String, Object> m = JsonUtils.toMap(json);\n} catch (RuntimeException e) {\n    throw new IllegalStateException(\"cannot parse json map: \" + e.getCause().getMessage(), e);\n}","preventionTips":["Use Map<String,Object> for heterogeneous value types to avoid binding mismatches","Validate JSON snippets with an external parser before embedding them in code","Handle empty input before calling toMap"],"tags":["jackson","deserialization","map"],"backgroundTag":"json-unmarshal-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"}