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
- Validate/normalize the JSON string before decoding (use a strict JSON producer)
- Check the string is non-empty and well-formed; log it on failure to spot the syntax issue
- 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
- Never hand-build JSON with string concatenation; use writeAsJsonString
- Reject empty/whitespace strings before decoding
- Log the offending string (safely truncated) when a MarshalException occurs
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
- Error decoding JSON bytes:
- Error writing as JSON:
- Could not decode JSON string as a map
- Couldn't parser stats json
- (dynamic MarshalException message)
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)
{
tryView on GitHub (pinned to 88fd0f6a0e)