apache/cassandra · error · MarshalException

Error decoding JSON bytes:

Error message

Error decoding JSON bytes: 

What it means

JsonUtils.decodeJson(byte[]) parses JSON bytes with Jackson's ObjectMapper. If the bytes are not valid JSON (malformed syntax, wrong encoding, or an I/O problem), it rethrows as MarshalException 'Error decoding JSON bytes: <message>'.

Solutions

  1. Verify the byte content is valid UTF-8 and complete JSON (e.g. dump as a String to inspect)
  2. Ensure the producer wrote the JSON with JsonUtils.writeAsJsonBytes or equivalent standard encoder
  3. Catch MarshalException at the call site and handle the corrupt payload

Example fix

// before
Object v = JsonUtils.decodeJson(bytes);
// after
try {
    Object v = JsonUtils.decodeJson(bytes);
} catch (MarshalException e) {
    logger.warn("Corrupt JSON payload: {}", e.getMessage());
}
Defensive patterns

Strategy: try-catch

Validate before calling

// sanity check before decode
if (bytes == null || bytes.length == 0) throw new IllegalArgumentException("empty JSON payload");

Try / catch

try { return JsonUtils.decodeJson(bytes); } catch (MarshalException e) { throw new InvalidRequestException("Invalid JSON payload: " + e.getMessage()); }

Prevention

When it happens

Trigger: Calling JsonUtils.decodeJson(byte[]) with bytes that are truncated, corrupted, in a non-UTF-8 encoding, or not JSON at all.

Common situations: Reading JSON blobs from storage that were written by another tool or truncated; deserializing CQL JSON columns with binary garbage; charset mismatches.

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/4e2fd907ecf2e7ba. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/utils/JsonUtils.java:89

    /**
     * Quotes string contents using standard JSON quoting.
     */
    public static String quoteAsJsonString(String s)
    {
        // In future should update to directly use `JsonStringEncoder.getInstance()` but for now:
        return new String(BufferRecyclers.getJsonStringEncoder().quoteAsString(s));
    }

    public static Object decodeJson(byte[] json)
    {
        try
        {
            return JSON_OBJECT_MAPPER.readValue(json, Object.class);
        }
        catch (IOException ex)
        {
            throw new MarshalException("Error decoding JSON bytes: " + ex.getMessage());
        }
    }

    public static Object decodeJson(String json)
    {
        try
        {
            return JSON_OBJECT_MAPPER.readValue(json, Object.class);
        }
        catch (IOException ex)
        {
            throw new MarshalException("Error decoding JSON string: " + ex.getMessage());
        }
    }

    public static byte[] writeAsJsonBytes(Object value)
    {
        try

View on GitHub (pinned to 88fd0f6a0e)