apache/cassandra · error · MarshalException

Expected a string representation of a date value, but got a

Error message

Expected a string representation of a date value, but got a %s: %s

What it means

SimpleDateType.fromJSONObject expects the parsed JSON value for a date column to be a string in CQL date form (yyyy-mm-dd). If the JSON value is not a string (number, boolean, object, null), the cast to String raises ClassCastException which is converted into this MarshalException.

Solutions

  1. Send the date as a JSON string formatted 'yyyy-mm-dd'.
  2. Convert epoch-day numbers to the date string on the client before sending.
  3. Reject/normalize the payload with a schema validator before calling Cassandra.

Example fix

// before
{"d": 20260909}
// after
{"d": "2026-09-09"}
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(parsed instanceof String)) throw new IllegalArgumentException("date must be a 'yyyy-MM-dd' string");

Type guard

boolean isDateString(Object v) { return v instanceof String && v.toString().matches("\\d{4}-\\d{2}-\\d{2}"); }

Try / catch

try { return SimpleDateType.instance.fromJSONObject(parsed); } catch (MarshalException e) { /* handle non-string JSON */ }

Prevention

When it happens

Trigger: INSERT ... JSON / fromJson() where a date column receives a JSON number, boolean, null, array or object instead of a quoted 'yyyy-mm-dd' string.

Common situations: Clients sending epoch days as a JSON number for a date column; JavaScript Date objects serialized to ISO timestamps or nulls instead of CQL date strings.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/147370cd79fa3d6f. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/db/marshal/SimpleDateType.java:91

    {
        return SimpleDateSerializer.dayToTimeInMillis(ByteBufferUtil.toInt(buffer));
    }

    @Override
    public boolean isValueCompatibleWithInternal(AbstractType<?> otherType)
    {
        return this == otherType || otherType == Int32Type.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 date value, but got a %s: %s",
                    parsed.getClass().getSimpleName(), parsed));
        }
    }

    @Override
    public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)
    {
        return '"' + SimpleDateSerializer.instance.toString(SimpleDateSerializer.instance.deserialize(buffer)) + '"';
    }

    @Override
    public CQL3Type asCQL3Type()
    {
        return CQL3Type.Native.DATE;
    }

    public TypeSerializer<Integer> getSerializer()

View on GitHub (pinned to 88fd0f6a0e)