apache/cassandra · error · MarshalException

Error decoding JSON string:

Error message

Error decoding JSON string: 

What it means

JsonUtils.decodeJson(String) parses a JSON string with Jackson. On any Jackson IOException (malformed JSON, unexpected token, encoding issue) it wraps the cause in MarshalException 'Error decoding JSON string: <message>'.

Solutions

  1. Validate/normalize the JSON string before decoding (use a strict JSON producer)
  2. Check the string is non-empty and well-formed; log it on failure to spot the syntax issue
  3. Catch MarshalException and return a default or surface a user-friendly parse error

Example fix

// before
Object v = JsonUtils.decodeJson("{'a':1}"); // invalid JSON
// after
Object v = JsonUtils.decodeJson("{\"a\":1}");
Defensive patterns

Strategy: try-catch

Validate before calling

if (json == null || json.trim().isEmpty()) throw new IllegalArgumentException("empty JSON string");

Try / catch

try { return JsonUtils.decodeJson(json); } catch (MarshalException e) { logger.warn("Bad JSON: {}", json); throw new InvalidRequestException(e.getMessage()); }

Prevention

When it happens

Trigger: Calling JsonUtils.decodeJson(String) with malformed JSON such as single-quoted strings, trailing commas, unquoted keys, or empty/whitespace strings.

Common situations: Hand-edited JSON passed programmatically; JSON produced by non-Jackson serializers with syntax extensions; empty column values treated as JSON.

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

Appendix: source

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

        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
        {
            return JSON_OBJECT_MAPPER.writeValueAsBytes(value);
        }
        catch (IOException ex)
        {
            throw new MarshalException("Error writing as JSON: " + ex.getMessage());
        }
    }

    public static String writeAsJsonString(Object value)
    {
        try

View on GitHub (pinned to 88fd0f6a0e)