{"record":{"id":"1155dffb79e2e554","repo":"apache/cassandra","slug":"expected-a-float-value-but-got-a-s-s","errorCode":null,"errorMessage":"Expected a float value, but got a %s: %s","messagePattern":"Expected a float value, but got a (.+?): (.+?)","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/FloatType.java","lineNumber":109,"sourceCode":"      catch (NumberFormatException e1)\n      {\n          throw new MarshalException(String.format(\"Unable to make float 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).floatValue()));\n        }\n        catch (ClassCastException exc)\n        {\n            throw new MarshalException(String.format(\n                    \"Expected a float 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        Float 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":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/FloatType.java#L91-L127","documentation":"FloatType.fromJSONObject() deserializes a parsed JSON value into a float; after the string and Number paths it catches ClassCastException and throws this MarshalException. It means the JSON value passed to fromJSONObject was neither a String nor a Number (e.g. a Boolean, Map, or List), so the float conversion cast failed. Cassandra throws it because a float column can only be materialized from a textual or numeric JSON representation.","triggerScenarios":"Calling FloatType.instance.fromJSONObject(parsed, protocolVersion) where parsed is a JSON object that parsed to a non-String/non-Number class such as Boolean, Map, or List (the cast ((Number) parsed).floatValue() throws ClassCastException, rethrown as MarshalException).","commonSituations":"Inserting JSON like {\"f\": true} or {\"f\": [1,2]} into a float column via the JSON path; buggy client serializers emitting booleans/nulls for float fields; schema drift where a column changed type but old JSON payloads still flow.","solutions":["Ensure the JSON value for the float field is a number or numeric string before calling fromJSONObject","Fix the client/producer so it serializes the field as a JSON number (e.g. 3.14) instead of a boolean/array/object","If the field can legitimately be non-numeric, change the column type or drop/transform the value upstream","Wrap fromJSONObject in try-catch for MarshalException to reject the record with a clear validation message"],"exampleFix":"// before\nObject parsed = json.get(\"score\"); // Boolean.TRUE\nByteBuffer v = FloatType.instance.fromJSONObject(parsed, ProtocolVersion.V5);\n// after\nObject parsed = json.get(\"score\");\nif (!(parsed instanceof Number || parsed instanceof String))\n    throw new IllegalArgumentException(\"score must be a number or numeric string\");\nByteBuffer v = FloatType.instance.fromJSONObject(parsed, ProtocolVersion.V5);","handlingStrategy":"validation","validationCode":"if (!(parsed instanceof Number || parsed instanceof String))\n    throw new IllegalArgumentException(\"Expected a float (number or string), got: \" + parsed.getClass().getSimpleName());","typeGuard":"static boolean isFloatCompatible(Object v) { return v instanceof Number || v instanceof String; }","tryCatchPattern":"try { FloatType.instance.fromJSONObject(parsed, pv); } catch (MarshalException e) { /* reject record: non-numeric JSON value for float field */ }","preventionTips":["Emit float fields as JSON numbers from producers","Validate JSON field types against the table schema before insert","Never map booleans/arrays/objects into numeric columns","Add schema-conformance tests for JSON payloads"],"tags":["cassandra","marshalling","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-14T21:17:11.552Z"}