apache/cassandra · error · MarshalException
Expected a double value, but got a %s: %s
Error message
Expected a double value, but got a %s: %s
What it means
DoubleType.fromJSONObject() accepts either a JSON string (parsed via fromString) or a JSON number (converted with ((Number) parsed).doubleValue()). If the parsed JSON value is neither a String nor a Number (e.g. a boolean, object, array, or null), the ClassCastException is caught and a MarshalException is thrown naming the actual runtime type. This enforces that JSON inputs for double columns are numeric or numeric strings.
Source
Thrown at src/java/org/apache/cassandra/db/marshal/DoubleType.java:108
catch (NumberFormatException e1)
{
throw new MarshalException(String.format("Unable to make double from '%s'", source), e1);
}
}
@Override
public Term fromJSONObject(Object parsed) throws MarshalException
{
try
{
if (parsed instanceof String)
return new Constants.Value(fromString((String) parsed));
else
return new Constants.Value(getSerializer().serialize(((Number) parsed).doubleValue()));
}
catch (ClassCastException exc)
{
throw new MarshalException(String.format(
"Expected a double value, but got a %s: %s", parsed.getClass().getSimpleName(), parsed));
}
}
@Override
public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)
{
Double value = getSerializer().deserialize(buffer);
if (value == null)
return "\"\"";
// JSON does not support NaN, Infinity and -Infinity values. Most of the parser convert them into null.
if (value.isNaN() || value.isInfinite())
return "null";
return value.toString();
}
public CQL3Type asCQL3Type()
{View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Send a JSON number (e.g. 3.14) for double columns in JSON payloads
- If sending a string, ensure it is a valid double literal string like "3.14"
- Fix the client serializer so the field maps to a numeric JSON type, not boolean/object/null
- Use INSERT ... VALUES with typed bind variables instead of JSON when types must be explicit
Example fix
// before
{"score": true}
// after
{"score": 3.14} Defensive patterns
Strategy: type-guard
Type guard
boolean isDoubleCompatible(Object parsed) { return parsed instanceof Number || (parsed instanceof String && isValidDoubleLiteral((String) parsed)); } Try / catch
try { term = DoubleType.instance.fromJSONObject(parsed); } catch (MarshalException e) { throw new IllegalArgumentException("Double field must be a JSON number or numeric string", e); } Prevention
- Ensure JSON serializers map double fields to JSON numbers, not booleans/objects
- Strip nulls before INSERT JSON
- Validate JSON payload schema against the table's column types before sending
When it happens
Trigger: Posting JSON like {"col": true} or {"col": {"x": 1}} or {"col": null} to a double column through the JSON entry points that call fromJSONObject (e.g. INSERT JSON, fromJSONObject Term construction).
Common situations: Client JSON serializers encode a double column as a boolean or nested object; nulls are not stripped before JSON insert; a schema change turned a formerly-string column into double while payloads stayed unchanged.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Expected an ascii string, but got a %s: %s
- Expected an empty string, but got: %s
- Expected a float value, but got a %s: %s
- Expected a map, but got a %s: %s
- Expected a list (representing a set), but got a %s: %s
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/6a342aea8c6b8526.
Report an issue: GitHub.