apache/cassandra · error · MarshalException
Expected a boolean value, but got a %s: %s
Error message
Expected a boolean value, but got a %s: %s
What it means
BooleanType.fromJSONObject throws this when a JSON value for a boolean column is neither a JSON string nor a JSON boolean. Strings go through fromString; any other JSON type (number, object, array) is rejected with the Java class simple name and value in the message.
Source
Thrown at src/java/org/apache/cassandra/db/marshal/BooleanType.java:102
public ByteBuffer fromString(String source) throws MarshalException
{
if (source.isEmpty()|| source.equalsIgnoreCase(Boolean.FALSE.toString()))
return decompose(false);
if (source.equalsIgnoreCase(Boolean.TRUE.toString()))
return decompose(true);
throw new MarshalException(String.format("Unable to make boolean from '%s'", source));
}
@Override
public Term fromJSONObject(Object parsed) throws MarshalException
{
if (parsed instanceof String)
return new Constants.Value(fromString((String) parsed));
else if (!(parsed instanceof Boolean))
throw new MarshalException(String.format(
"Expected a boolean value, but got a %s: %s", parsed.getClass().getSimpleName(), parsed));
return new Constants.Value(getSerializer().serialize((Boolean) parsed));
}
@Override
public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)
{
return getSerializer().deserialize(buffer).toString();
}
public CQL3Type asCQL3Type()
{
return CQL3Type.Native.BOOLEAN;
}
public TypeSerializer<Boolean> getSerializer()
{View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Send a JSON boolean: {"flag": true} (or a quoted "true"/"false" string)
- Convert 0/1 to true/false in application code before JSON insert
- Change column type to tinyint if numeric flags are the real requirement
- Validate JSON payload against column types before sending
Example fix
// before
INSERT INTO t JSON '{"flag": 1}';
// after
INSERT INTO t JSON '{"flag": true}'; Defensive patterns
Strategy: type-guard
Validate before calling
Object v = jsonNode.isTextual() ? jsonNode.textValue() : (jsonNode.isBoolean() ? jsonNode.booleanValue() : REJECT);
Type guard
boolean isBooleanJson(Object v) { return v instanceof Boolean || (v instanceof String && (((String) v).equalsIgnoreCase("true") || ((String) v).equalsIgnoreCase("false"))); } Try / catch
try { Term t = boolType.fromJSONObject(parsed); } catch (MarshalException e) { if (e.getMessage().startsWith("Expected a boolean value")) { /* coerce 0/1 -> true/false */ } else throw e; } Prevention
- Send JSON booleans as true/false, never 1/0
- Configure serializers to emit native JSON booleans
- Validate payload schema before insert
- Coerce common 0/1 encodings client-side
When it happens
Trigger: INSERT INTO t JSON '{"flag": 1}' where flag is boolean (JSON number not allowed); fromJson() with numeric argument for boolean column; Term.fromJSONObject receiving e.g. Integer or Double for a boolean field.
Common situations: JSON APIs that encode booleans as 0/1; hand-written JSON payloads using unquoted 1/0; ORMs or serializers emitting integers for booleans; older payloads written before the column became boolean.
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
- Unable to make boolean from '%s'
- Expected a byte value, but got a %s: %s
- String representation of blob is missing 0x prefix: %s
- Value '%s' is not a valid blob representation: %s
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/e63d53c850f043ae.
Report an issue: GitHub.