apache/cassandra · error · MarshalException
Expected a string representation of a time value, but got a
Error message
Expected a string representation of a time value, but got a %s: %s
What it means
TimeType.fromJSONObject expects the parsed JSON value for a time column to be a string in CQL time form (hh:mm:ss[.fff] or nanoseconds since midnight). Any non-string JSON value causes a ClassCastException, converted to this MarshalException.
Solutions
- Send the time as a JSON string in CQL time format.
- Convert numeric nanoseconds/millis to the string form client-side.
- Validate the payload shape before submission.
Example fix
// before
{"t": 30600000}
// after
{"t": "08:30:00.000"} Defensive patterns
Strategy: type-guard
Validate before calling
if (!(parsed instanceof String)) throw new IllegalArgumentException("time must be an 'HH:mm:ss[.fff]' string"); Type guard
boolean isTimeString(Object v) { return v instanceof String && v.toString().matches("\\d{2}:\\d{2}(:\\d{2}(\\.\\d{1,9})?)?"); } Try / catch
try { return TimeType.instance.fromJSONObject(parsed); } catch (MarshalException e) { /* handle non-string JSON */ } Prevention
- Send times as CQL time strings, not epoch numbers
- Normalize language time objects to strings before serializing
- Validate payloads with a schema before INSERT JSON
When it happens
Trigger: INSERT ... JSON / fromJson() where a time column receives a JSON number, boolean, null, array or object instead of a quoted time string like '08:30:00.123'.
Common situations: Clients sending milliseconds-since-midnight as a number; JS Date/time objects serialized as non-strings; null for missing times.
Related errors
- Expected a double value, but got a
- Expected a float value, but got a
- Expected a list, but got a
- Expected a list (representing a set), but got a
- Expected a long or a datestring representation of a…
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/41ca34f0afb38392.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/db/marshal/TimeType.java:84
{
return ByteSourceInverse.getOptionalFixedLength(accessor, comparableBytes, 8);
}
@Override
public boolean isValueCompatibleWithInternal(AbstractType<?> otherType)
{
return this == otherType || otherType == LongType.instance;
}
public Term fromJSONObject(Object parsed) throws MarshalException
{
try
{
return new Constants.Value(fromString((String) parsed));
}
catch (ClassCastException exc)
{
throw new MarshalException(String.format(
"Expected a string representation of a time value, but got a %s: %s", parsed.getClass().getSimpleName(), parsed));
}
}
@Override
public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)
{
return '"' + TimeSerializer.instance.toString(TimeSerializer.instance.deserialize(buffer)) + '"';
}
@Override
public CQL3Type asCQL3Type()
{
return CQL3Type.Native.TIME;
}
@Override
public TypeSerializer<Long> getSerializer()View on GitHub (pinned to 88fd0f6a0e)