{"record":{"id":"f910653c468a9d2f","repo":"apache/cassandra","slug":"expected-a-long-or-a-datestring-representation-of","errorCode":null,"errorMessage":"Expected a long or a datestring representation of a date value, but got a %s: %s","messagePattern":"Expected a long or a datestring representation of a date value, but got a (.+?): (.+?)","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/DateType.java","lineNumber":93,"sourceCode":"      if (source.isEmpty())\n          return ByteBufferUtil.EMPTY_BYTE_BUFFER;\n\n      return ByteBufferUtil.bytes(TimestampSerializer.dateStringToTimestamp(source));\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 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 '\"' + TimestampSerializer.getJsonDateFormatter().format(TimestampSerializer.instance.deserialize(buffer).toInstant()) + '\"';\n    }\n\n    @Override\n    public boolean isCompatibleWith(AbstractType<?> previous)\n    {\n        if (super.isCompatibleWith(previous))\n            return true;\n\n        if (previous instanceof TimestampType)","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/DateType.java#L75-L111","documentation":"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.","triggerScenarios":"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\"}.","commonSituations":"JSON import tooling (COPY FROM / cqlsh / custom loaders) emitting unquoted numbers or objects for date columns; scripting against cqlsh JSON input.","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"],"exampleFix":"// before\n{\"created\": 1735689600000}\n// after\n{\"created\": \"1735689600000\"}  // or \"2024-01-01 00:00:00+0000\"","handlingStrategy":"type-guard","validationCode":"if (!(jsonValue instanceof String)) throw new IllegalArgumentException(\"date JSON field must be a string: long epoch or datestring\");","typeGuard":"boolean isDateString(Object v) { return v instanceof String; }","tryCatchPattern":"try { DateType.instance.fromJSONObject(obj); } catch (MarshalException e) { /* retry as string, log offending field */ }","preventionTips":["Always serialize date fields as JSON strings","Validate JSON documents against a schema before import","Normalize epoch millis to strings in ETL code"],"tags":["json","date","marshal"],"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"}