apache/cassandra · error · MarshalException
Value '%s' is not a valid representation of a decimal value
Error message
Value '%s' is not a valid representation of a decimal value
What it means
DecimalType.fromJSONObject converts the JSON value to a string and calls fromString; NumberFormatException or MarshalException from that parse is rethrown as this MarshalException naming the offending JSON value. It exists to give JSON-import flows a clear, value-specific message.
Source
Thrown at src/java/org/apache/cassandra/db/marshal/DecimalType.java:309
}
catch (Exception e)
{
throw new MarshalException(String.format("unable to make BigDecimal from '%s'", source), e);
}
return decompose(decimal);
}
@Override
public Term fromJSONObject(Object parsed) throws MarshalException
{
try
{
return new Constants.Value(fromString(Objects.toString(parsed)));
}
catch (NumberFormatException | MarshalException exc)
{
throw new MarshalException(String.format("Value '%s' is not a valid representation of a decimal value", parsed));
}
}
@Override
public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)
{
return Objects.toString(getSerializer().deserialize(buffer), "\"\"");
}
public CQL3Type asCQL3Type()
{
return CQL3Type.Native.DECIMAL;
}
public TypeSerializer<BigDecimal> getSerializer()
{
return DecimalSerializer.instance;
}View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Fix the JSON document so the decimal field is a number or a valid decimal string
- Coerce/validate the field before calling fromJSONObject
- Map bad rows to a dead-letter log instead of failing the whole import
Example fix
// before
{"amount": "12.3.4"}
// after
{"amount": "12.34"} Defensive patterns
Strategy: try-catch
Validate before calling
Object v = json.get("amount"); boolean ok = v instanceof Number || (v instanceof String && isDecimalLiteral((String) v)); Type guard
boolean isValidDecimalJson(Object v) { return v instanceof Number || (v instanceof String && v.toString().matches("[+-]?\\d+(\\.\\d+)?")); } Try / catch
try { DecimalType.instance.fromJSONObject(parsed); } catch (MarshalException e) { /* log parsed value, route row to error queue */ } Prevention
- Pre-validate JSON decimal fields (number or numeric string)
- Reject booleans/nulls at the JSON schema level
- Handle per-row failures instead of aborting the whole import
When it happens
Trigger: fromJSONObject invoked with a JSON value whose string form is not a valid decimal (e.g. true, null-converted string, '12.3.4').
Common situations: COPY FROM JSON, cqlsh JSON input, or driver JSON serialization emitting booleans/nulls/strings into decimal columns.
Related errors
- (dynamic MarshalException message)
- Expected an ascii string, but got a %s: %s
- Expected a boolean value, but got a %s: %s
- Expected a byte value, but got a %s: %s
- String representation of blob is missing 0x prefix: %s
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/bb9625cf95a924a4.
Report an issue: GitHub.