{"record":{"id":"6a342aea8c6b8526","repo":"apache/cassandra","slug":"expected-a-double-value-but-got-a-s-s","errorCode":null,"errorMessage":"Expected a double value, but got a %s: %s","messagePattern":"Expected a double value, but got a (.+?): (.+?)","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/DoubleType.java","lineNumber":108,"sourceCode":"      catch (NumberFormatException e1)\n      {\n          throw new MarshalException(String.format(\"Unable to make double from '%s'\", source), e1);\n      }\n    }\n\n    @Override\n    public Term fromJSONObject(Object parsed) throws MarshalException\n    {\n        try\n        {\n            if (parsed instanceof String)\n                return new Constants.Value(fromString((String) parsed));\n            else\n                return new Constants.Value(getSerializer().serialize(((Number) parsed).doubleValue()));\n        }\n        catch (ClassCastException exc)\n        {\n            throw new MarshalException(String.format(\n                    \"Expected a double 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        Double value = getSerializer().deserialize(buffer);\n        if (value == null)\n            return \"\\\"\\\"\";\n        // JSON does not support NaN, Infinity and -Infinity values. Most of the parser convert them into null.\n        if (value.isNaN() || value.isInfinite())\n            return \"null\";\n        return value.toString();\n    }\n\n    public CQL3Type asCQL3Type()\n    {","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/DoubleType.java#L90-L126","documentation":"DoubleType.fromJSONObject() accepts either a JSON string (parsed via fromString) or a JSON number (converted with ((Number) parsed).doubleValue()). If the parsed JSON value is neither a String nor a Number (e.g. a boolean, object, array, or null), the ClassCastException is caught and a MarshalException is thrown naming the actual runtime type. This enforces that JSON inputs for double columns are numeric or numeric strings.","triggerScenarios":"Posting JSON like {\"col\": true} or {\"col\": {\"x\": 1}} or {\"col\": null} to a double column through the JSON entry points that call fromJSONObject (e.g. INSERT JSON, fromJSONObject Term construction).","commonSituations":"Client JSON serializers encode a double column as a boolean or nested object; nulls are not stripped before JSON insert; a schema change turned a formerly-string column into double while payloads stayed unchanged.","solutions":["Send a JSON number (e.g. 3.14) for double columns in JSON payloads","If sending a string, ensure it is a valid double literal string like \"3.14\"","Fix the client serializer so the field maps to a numeric JSON type, not boolean/object/null","Use INSERT ... VALUES with typed bind variables instead of JSON when types must be explicit"],"exampleFix":"// before\n{\"score\": true}\n// after\n{\"score\": 3.14}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"boolean isDoubleCompatible(Object parsed) { return parsed instanceof Number || (parsed instanceof String && isValidDoubleLiteral((String) parsed)); }","tryCatchPattern":"try { term = DoubleType.instance.fromJSONObject(parsed); } catch (MarshalException e) { throw new IllegalArgumentException(\"Double field must be a JSON number or numeric string\", e); }","preventionTips":["Ensure JSON serializers map double fields to JSON numbers, not booleans/objects","Strip nulls before INSERT JSON","Validate JSON payload schema against the table's column types before sending"],"tags":["cassandra","json","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-14T16:17:12.679Z"}