apache/cassandra · error · MarshalException
Expected a long or a datestring representation of a…
Error message
Expected a long or a datestring representation of a timestamp value, but got a %s: %s
What it means
TimestampType.fromJSONObject accepts either a JSON string (datestring parseable by fromString) or a number (epoch millis). Any other JSON type raises ClassCastException which is wrapped as this MarshalException explaining both accepted forms.
Solutions
- Send epoch-millis as a JSON number or a parseable date string (e.g. '2015-05-03 13:30:54.234').
- Normalize client date objects to strings/millis before serialization.
- Validate the JSON schema before submitting.
Example fix
// before
{"ts": {"$date": "2026-09-09T00:00:00Z"}}
// after
{"ts": "2026-09-09 00:00:00"} Defensive patterns
Strategy: type-guard
Validate before calling
if (!(parsed instanceof String || parsed instanceof Number)) throw new IllegalArgumentException("timestamp must be epoch-millis number or date string"); Type guard
boolean isTimestampLike(Object v) { return v instanceof String || v instanceof Number; } Try / catch
try { return TimestampType.instance.fromJSONObject(parsed); } catch (MarshalException e) { /* handle bad JSON type */ } Prevention
- Serialize timestamps as epoch millis (number) or CQL-parseable strings
- Never emit client date objects (e.g. {"$date": ...}) directly
- Schema-validate outbound JSON
When it happens
Trigger: INSERT ... JSON / fromJson() where a timestamp column receives a JSON boolean, null, array or object rather than a string or number.
Common situations: ISODate/object serialization from MongoDB-style clients; null for missing timestamps; client sending nested objects for date fields.
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 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 map, but got a
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/10534b28ba825123.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/db/marshal/TimestampType.java:119
@Override
public long toTimeInMillis(ByteBuffer value)
{
return ByteBufferUtil.toLong(value);
}
@Override
public Term fromJSONObject(Object parsed) throws MarshalException
{
if (parsed instanceof Long)
return new Constants.Value(ByteBufferUtil.bytes((Long) parsed));
try
{
return new Constants.Value(TimestampType.instance.fromString((String) parsed));
}
catch (ClassCastException exc)
{
throw new MarshalException(String.format(
"Expected a long or a datestring representation of a timestamp value, but got a %s: %s",
parsed.getClass().getSimpleName(), parsed));
}
}
private String toString(Date date)
{
return date != null ? TimestampSerializer.getJsonDateFormatter().format(date.toInstant()) : "";
}
@Override
public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)
{
return '"' + toString(TimestampSerializer.instance.deserialize(buffer)) + '"';
}
@Override
public boolean isCompatibleWith(AbstractType<?> previous)View on GitHub (pinned to 88fd0f6a0e)