apache/cassandra · error · InvalidRequestException

(dynamic MarshalException message)

Error message

(dynamic MarshalException message)

What it means

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.

Source

Thrown at src/java/org/apache/cassandra/cql3/Json.java:323

                    }
                }
            }

            if (!valueMap.isEmpty())
            {
                throw new InvalidRequestException(format("JSON values map contains unrecognized column: %s",
                                                         valueMap.keySet().iterator().next()));
            }

            return columnMap;
        }
        catch (IOException exc)
        {
            throw new InvalidRequestException(format("Could not decode JSON string as a map: %s. (String was: %s)", exc.toString(), jsonString));
        }
        catch (MarshalException exc)
        {
            throw new InvalidRequestException(exc.getMessage());
        }
    }
}

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Read the dynamic message for the exact failing element
  2. Ensure JSON keys don't collide when lowercased; quote keys for case-sensitive identifiers
  3. Match nested JSON shapes to collection/UDT definitions (lists as arrays, maps as objects, tuples as arrays)
  4. Test the same payload via cqlsh to isolate driver-side formatting issues

Example fix

// before
{"Name": "a", "name": "b"} // case-colliding keys
// after
{"name": "b"}
Defensive patterns

Strategy: try-catch

Validate before calling

// check key collisions after lowercasing (what handleCaseSensitivity enforces)
java.util.Set<String> seen = new java.util.HashSet<>();
for (String k : parsedJson.keySet())
    if (!seen.add(k.toLowerCase())) throw new IllegalArgumentException("Duplicate key after lowercasing: " + k);

Try / catch

try { session.execute("INSERT INTO t JSON ?", json); } catch (InvalidRequestException e) { log.error("JSON marshal failed: {} payload={}", e.getMessage(), json, e); throw e; }

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/4d5c5af7fc9094b4. Report an issue: GitHub.