{"record":{"id":"147370cd79fa3d6f","repo":"apache/cassandra","slug":"expected-a-string-representation-of-a-date-value","errorCode":null,"errorMessage":"Expected a string representation of a date value, but got a %s: %s","messagePattern":"Expected a string representation of a date value, but got a (.+?): (.+?)","errorType":"exception","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/SimpleDateType.java","lineNumber":91,"sourceCode":"    {\n        return SimpleDateSerializer.dayToTimeInMillis(ByteBufferUtil.toInt(buffer));\n    }\n\n    @Override\n    public boolean isValueCompatibleWithInternal(AbstractType<?> otherType)\n    {\n        return this == otherType || otherType == Int32Type.instance;\n    }\n\n    public Term fromJSONObject(Object parsed) throws MarshalException\n    {\n        try\n        {\n            return new Constants.Value(fromString((String) parsed));\n        }\n        catch (ClassCastException exc)\n        {\n            throw new MarshalException(String.format(\n                    \"Expected a string representation of a date value, but got a %s: %s\",\n                    parsed.getClass().getSimpleName(), parsed));\n        }\n    }\n\n    @Override\n    public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)\n    {\n        return '\"' + SimpleDateSerializer.instance.toString(SimpleDateSerializer.instance.deserialize(buffer)) + '\"';\n    }\n\n    @Override\n    public CQL3Type asCQL3Type()\n    {\n        return CQL3Type.Native.DATE;\n    }\n\n    public TypeSerializer<Integer> getSerializer()","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/SimpleDateType.java#L73-L109","documentation":"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.","triggerScenarios":"INSERT ... JSON / fromJson() where a date column receives a JSON number, boolean, null, array or object instead of a quoted 'yyyy-mm-dd' string.","commonSituations":"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.","solutions":["Send the date as a JSON string formatted 'yyyy-mm-dd'.","Convert epoch-day numbers to the date string on the client before sending.","Reject/normalize the payload with a schema validator before calling Cassandra."],"exampleFix":"// before\n{\"d\": 20260909}\n// after\n{\"d\": \"2026-09-09\"}","handlingStrategy":"type-guard","validationCode":"if (!(parsed instanceof String)) throw new IllegalArgumentException(\"date must be a 'yyyy-MM-dd' string\");","typeGuard":"boolean isDateString(Object v) { return v instanceof String && v.toString().matches(\"\\\\d{4}-\\\\d{2}-\\\\d{2}\"); }","tryCatchPattern":"try { return SimpleDateType.instance.fromJSONObject(parsed); } catch (MarshalException e) { /* handle non-string JSON */ }","preventionTips":["Serialize dates as CQL 'yyyy-MM-dd' strings, never epoch numbers","Use a JSON schema validator on outbound payloads","Convert java.time.LocalDate with toString() before sending"],"tags":["cassandra","json","date","type-mismatch"],"backgroundTag":"invalid-date-format","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}