{"record":{"id":"41ca34f0afb38392","repo":"apache/cassandra","slug":"expected-a-string-representation-of-a-time-value","errorCode":null,"errorMessage":"Expected a string representation of a time value, but got a %s: %s","messagePattern":"Expected a string representation of a time value, but got a (.+?): (.+?)","errorType":"exception","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/TimeType.java","lineNumber":84,"sourceCode":"    {\n        return ByteSourceInverse.getOptionalFixedLength(accessor, comparableBytes, 8);\n    }\n\n    @Override\n    public boolean isValueCompatibleWithInternal(AbstractType<?> otherType)\n    {\n        return this == otherType || otherType == LongType.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 time value, but got a %s: %s\", parsed.getClass().getSimpleName(), parsed));\n        }\n    }\n\n    @Override\n    public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)\n    {\n        return '\"' + TimeSerializer.instance.toString(TimeSerializer.instance.deserialize(buffer)) + '\"';\n    }\n\n    @Override\n    public CQL3Type asCQL3Type()\n    {\n        return CQL3Type.Native.TIME;\n    }\n\n    @Override\n    public TypeSerializer<Long> getSerializer()","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/TimeType.java#L66-L102","documentation":"TimeType.fromJSONObject expects the parsed JSON value for a time column to be a string in CQL time form (hh:mm:ss[.fff] or nanoseconds since midnight). Any non-string JSON value causes a ClassCastException, converted to this MarshalException.","triggerScenarios":"INSERT ... JSON / fromJson() where a time column receives a JSON number, boolean, null, array or object instead of a quoted time string like '08:30:00.123'.","commonSituations":"Clients sending milliseconds-since-midnight as a number; JS Date/time objects serialized as non-strings; null for missing times.","solutions":["Send the time as a JSON string in CQL time format.","Convert numeric nanoseconds/millis to the string form client-side.","Validate the payload shape before submission."],"exampleFix":"// before\n{\"t\": 30600000}\n// after\n{\"t\": \"08:30:00.000\"}","handlingStrategy":"type-guard","validationCode":"if (!(parsed instanceof String)) throw new IllegalArgumentException(\"time must be an 'HH:mm:ss[.fff]' string\");","typeGuard":"boolean isTimeString(Object v) { return v instanceof String && v.toString().matches(\"\\\\d{2}:\\\\d{2}(:\\\\d{2}(\\\\.\\\\d{1,9})?)?\"); }","tryCatchPattern":"try { return TimeType.instance.fromJSONObject(parsed); } catch (MarshalException e) { /* handle non-string JSON */ }","preventionTips":["Send times as CQL time strings, not epoch numbers","Normalize language time objects to strings before serializing","Validate payloads with a schema before INSERT JSON"],"tags":["cassandra","json","time","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"}