{"record":{"id":"4d5c5af7fc9094b4","repo":"apache/cassandra","slug":"dynamic-marshalexception-message","errorCode":null,"errorMessage":"(dynamic MarshalException message)","messagePattern":"\\(dynamic MarshalException message\\)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/Json.java","lineNumber":323,"sourceCode":"                    }\n                }\n            }\n\n            if (!valueMap.isEmpty())\n            {\n                throw new InvalidRequestException(format(\"JSON values map contains unrecognized column: %s\",\n                                                         valueMap.keySet().iterator().next()));\n            }\n\n            return columnMap;\n        }\n        catch (IOException exc)\n        {\n            throw new InvalidRequestException(format(\"Could not decode JSON string as a map: %s. (String was: %s)\", exc.toString(), jsonString));\n        }\n        catch (MarshalException exc)\n        {\n            throw new InvalidRequestException(exc.getMessage());\n        }\n    }\n}\n","sourceCodeStart":305,"sourceCodeEnd":327,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/Json.java#L305-L327","documentation":"Json.parseJson also catches MarshalException (raised inside JSON value handling outside the per-column decode wrapper) and rethrows it as an InvalidRequestException carrying the original dynamic message. The specific text depends on where the marshal failed — e.g. handleCaseSensitivity duplicate-key checks or nested term parsing — and is surfaced verbatim to the client.","triggerScenarios":"INSERT INTO t JSON where a MarshalException escapes the per-column catch: invalid nested collection/tuple/user-type JSON structure, or case-sensitivity violations in keys (handleCaseSensitivity throwing MarshalException).","commonSituations":"JSON keys that differ only by case for a case-insensitive schema (e.g. {\"Name\":..,\"name\":..}); malformed nested structures for frozen collections/UDTs that fail during Term preparation.","solutions":["Read the dynamic message for the exact failing element","Ensure JSON keys don't collide when lowercased; quote keys for case-sensitive identifiers","Match nested JSON shapes to collection/UDT definitions (lists as arrays, maps as objects, tuples as arrays)","Test the same payload via cqlsh to isolate driver-side formatting issues"],"exampleFix":"// before\n{\"Name\": \"a\", \"name\": \"b\"} // case-colliding keys\n// after\n{\"name\": \"b\"}","handlingStrategy":"try-catch","validationCode":"// check key collisions after lowercasing (what handleCaseSensitivity enforces)\njava.util.Set<String> seen = new java.util.HashSet<>();\nfor (String k : parsedJson.keySet())\n    if (!seen.add(k.toLowerCase())) throw new IllegalArgumentException(\"Duplicate key after lowercasing: \" + k);","typeGuard":null,"tryCatchPattern":"try { session.execute(\"INSERT INTO t JSON ?\", json); } catch (InvalidRequestException e) { log.error(\"JSON marshal failed: {} payload={}\", e.getMessage(), json, e); throw e; }","preventionTips":["Avoid JSON keys differing only by case","Match nested structures to collection/UDT definitions exactly","Test nested payloads (maps, tuples, UDTs) against the schema","Read the dynamic MarshalException message — it names the failing element"],"tags":["cql","json","marshal"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}