{"record":{"id":"9a02b195cfaf0300","repo":"apache/cassandra","slug":"error-decoding-json","errorCode":null,"errorMessage":"Error decoding JSON: ","messagePattern":"Error decoding JSON: ","errorType":"exception","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/utils/JsonUtils.java","lineNumber":161,"sourceCode":"        try\n        {\n            return JSON_OBJECT_MAPPER.readValue(json, Map.class);\n        }\n        catch (IOException ex)\n        {\n            throw new MarshalException(\"Error decoding JSON string: \" + ex.getMessage());\n        }\n    }\n\n    public static <T> Map<String, T> fromJsonMap(byte[] bytes)\n    {\n        try\n        {\n            return JSON_OBJECT_MAPPER.readValue(bytes, Map.class);\n        }\n        catch (IOException ex)\n        {\n            throw new MarshalException(\"Error decoding JSON: \" + ex.getMessage());\n        }\n    }\n\n    public static List<String> fromJsonList(byte[] bytes)\n    {\n        try\n        {\n            return JSON_OBJECT_MAPPER.readValue(bytes, List.class);\n        }\n        catch (IOException ex)\n        {\n            throw new MarshalException(\"Error decoding JSON: \" + ex.getMessage());\n        }\n    }\n\n    public static List<String> fromJsonList(String json)\n    {\n        try","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/utils/JsonUtils.java#L143-L179","documentation":"JsonUtils.fromJsonMap deserializes a byte array into a Map using Jackson. If Jackson cannot parse the bytes as JSON (malformed syntax, wrong encoding) it throws IOException, which is wrapped in a MarshalException prefixed with 'Error decoding JSON: '. The original Jackson message is appended, so the detail is in the exception text.","triggerScenarios":"Calling JsonUtils.fromJsonMap(byte[]) with bytes that are not valid JSON object text: truncated input, non-UTF8 bytes, JSON arrays or scalars when a Map is expected, or corrupt values stored in the database.","commonSituations":"Decoding a collection-typed column value written by a different application/version; hand-edited CQL literal values; data migrated from another format; reading legacy JSON stored without proper validation.","solutions":["Print the full MarshalException message to see the underlying Jackson parse error","Validate the byte payload with a JSON validator before decoding","Confirm the source of the bytes (column value vs user input) and that it was produced by JsonUtils.serializeToJsonString","Check JVM file.encoding/charset consistency; pass UTF-8 encoded bytes"],"exampleFix":"// before\nMap<String, String> m = JsonUtils.fromJsonMap(rawBytes);\n// after\nString json = new String(rawBytes, StandardCharsets.UTF_8);\nif (!json.trim().startsWith(\"{\")) throw new IllegalArgumentException(\"Not a JSON object: \" + json);\nMap<String, String> m = JsonUtils.fromJsonMap(rawBytes);","handlingStrategy":"try-catch","validationCode":"// Java\npublic static Map<String, String> safeFromJsonMap(byte[] bytes) {\n    String s = new String(bytes, StandardCharsets.UTF_8).trim();\n    if (!s.startsWith(\"{\")) throw new IllegalArgumentException(\"Not a JSON object: \" + s);\n    return JsonUtils.fromJsonMap(bytes);\n}","typeGuard":"static boolean isJsonObject(byte[] b) {\n    if (b == null || b.length == 0) return false;\n    String s = new String(b, StandardCharsets.UTF_8).trim();\n    return s.startsWith(\"{\") && s.endsWith(\"}\");\n}","tryCatchPattern":"try {\n    Map<String, String> m = JsonUtils.fromJsonMap(bytes);\n} catch (MarshalException e) {\n    logger.error(\"JSON map decode failed: {}\", e.getMessage());\n    // fall back to default / reject record\n}","preventionTips":["Always serialize with JsonUtils/Jackson, never by string concatenation","Validate user-supplied JSON with a linter before storing","Keep payloads UTF-8 encoded end-to-end","Log the raw payload on decode failure for diagnosis"],"tags":["json","deserialization","cassandra"],"backgroundTag":"json-decode-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}