{"record":{"id":"10534b28ba825123","repo":"apache/cassandra","slug":"expected-a-long-or-a-datestring-representation-of-10534b","errorCode":null,"errorMessage":"Expected a long or a datestring representation of a timestamp value, but got a %s: %s","messagePattern":"Expected a long or a datestring representation of a timestamp value, but got a (.+?): (.+?)","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/TimestampType.java","lineNumber":119,"sourceCode":"    @Override\n    public long toTimeInMillis(ByteBuffer value)\n    {\n        return ByteBufferUtil.toLong(value);\n    }\n\n    @Override\n    public Term fromJSONObject(Object parsed) throws MarshalException\n    {\n        if (parsed instanceof Long)\n            return new Constants.Value(ByteBufferUtil.bytes((Long) parsed));\n\n        try\n        {\n            return new Constants.Value(TimestampType.instance.fromString((String) parsed));\n        }\n        catch (ClassCastException exc)\n        {\n            throw new MarshalException(String.format(\n                    \"Expected a long or a datestring representation of a timestamp value, but got a %s: %s\",\n                    parsed.getClass().getSimpleName(), parsed));\n        }\n    }\n\n    private String toString(Date date)\n    {\n        return date != null ? TimestampSerializer.getJsonDateFormatter().format(date.toInstant()) : \"\";\n    }\n\n    @Override\n    public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)\n    {\n        return '\"' + toString(TimestampSerializer.instance.deserialize(buffer)) + '\"';\n    }\n\n    @Override\n    public boolean isCompatibleWith(AbstractType<?> previous)","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/TimestampType.java#L101-L137","documentation":"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.","triggerScenarios":"INSERT ... JSON / fromJson() where a timestamp column receives a JSON boolean, null, array or object rather than a string or number.","commonSituations":"ISODate/object serialization from MongoDB-style clients; null for missing timestamps; client sending nested objects for date fields.","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."],"exampleFix":"// before\n{\"ts\": {\"$date\": \"2026-09-09T00:00:00Z\"}}\n// after\n{\"ts\": \"2026-09-09 00:00:00\"}","handlingStrategy":"type-guard","validationCode":"if (!(parsed instanceof String || parsed instanceof Number)) throw new IllegalArgumentException(\"timestamp must be epoch-millis number or date string\");","typeGuard":"boolean isTimestampLike(Object v) { return v instanceof String || v instanceof Number; }","tryCatchPattern":"try { return TimestampType.instance.fromJSONObject(parsed); } catch (MarshalException e) { /* handle bad JSON type */ }","preventionTips":["Serialize timestamps as epoch millis (number) or CQL-parseable strings","Never emit client date objects (e.g. {\"$date\": ...}) directly","Schema-validate outbound JSON"],"tags":["cassandra","json","timestamp","type-mismatch"],"backgroundTag":"type-mismatch","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"}