apache/cassandra · error · MarshalException
Expected a long or a datestring representation of a date…
Error message
Expected a long or a datestring representation of a date value, but got a %s: %s
What it means
DateType.fromJSONObject parses a JSON value as a date: it expects a string containing either a long (epoch millis) or a datestring, parsed via TimestampType. If the JSON value is not a String (e.g. a JSON number or object), the ClassCastException is converted into this MarshalException telling you the actual Java type received.
Solutions
- Quote the date value as a JSON string containing a long or datestring
- Pre-convert numeric epoch millis to a string before import
- Parse/normalize the JSON document before passing to fromJSONObject
Example fix
// before
{"created": 1735689600000}
// after
{"created": "1735689600000"} // or "2024-01-01 00:00:00+0000" Defensive patterns
Strategy: type-guard
Validate before calling
if (!(jsonValue instanceof String)) throw new IllegalArgumentException("date JSON field must be a string: long epoch or datestring"); Type guard
boolean isDateString(Object v) { return v instanceof String; } Try / catch
try { DateType.instance.fromJSONObject(obj); } catch (MarshalException e) { /* retry as string, log offending field */ } Prevention
- Always serialize date fields as JSON strings
- Validate JSON documents against a schema before import
- Normalize epoch millis to strings in ETL code
When it happens
Trigger: Calling fromJSONObject with a JSON node that is not a string, e.g. {"d": 1234567890} instead of {"d": "1234567890"} or {"d": "2015-05-01 13:00:00+0000"}.
Common situations: JSON import tooling (COPY FROM / cqlsh / custom loaders) emitting unquoted numbers or objects for date columns; scripting against cqlsh JSON input.
Related errors
- (dynamic MarshalException message)
- Expected a boolean value, but got a
- Expected a byte value, but got a
- Expected a list, but got a
- Expected a short value, but got a
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/f910653c468a9d2f.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/db/marshal/DateType.java:93
if (source.isEmpty())
return ByteBufferUtil.EMPTY_BYTE_BUFFER;
return ByteBufferUtil.bytes(TimestampSerializer.dateStringToTimestamp(source));
}
@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 date value, but got a %s: %s",
parsed.getClass().getSimpleName(), parsed));
}
}
@Override
public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)
{
return '"' + TimestampSerializer.getJsonDateFormatter().format(TimestampSerializer.instance.deserialize(buffer).toInstant()) + '"';
}
@Override
public boolean isCompatibleWith(AbstractType<?> previous)
{
if (super.isCompatibleWith(previous))
return true;
if (previous instanceof TimestampType)View on GitHub (pinned to 88fd0f6a0e)