{"record":{"id":"8906328759370f23","repo":"apache/cassandra","slug":"expected-an-int-value-but-got-a-s-s","errorCode":null,"errorMessage":"Expected an int value, but got a %s: %s","messagePattern":"Expected an int value, but got a (.+?): (.+?)","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/Int32Type.java","lineNumber":115,"sourceCode":"        catch (Exception e)\n        {\n            throw new MarshalException(String.format(\"Unable to make int from '%s'\", source), e);\n        }\n\n        return decompose(int32Type);\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\n            Number parsedNumber = (Number) parsed;\n            if (!(parsedNumber instanceof Integer))\n                throw new MarshalException(String.format(\"Expected an int value, but got a %s: %s\", parsed.getClass().getSimpleName(), parsed));\n\n            return new Constants.Value(getSerializer().serialize(parsedNumber.intValue()));\n        }\n        catch (ClassCastException exc)\n        {\n            throw new MarshalException(String.format(\n                    \"Expected an int 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 Objects.toString(getSerializer().deserialize(buffer), \"\\\"\\\"\");\n    }\n\n    public CQL3Type asCQL3Type()\n    {","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/Int32Type.java#L97-L133","documentation":"Int32Type.fromJSONObject() accepts a JSON String (parsed via fromString) or a Number (cast and converted with intValue()); a value of any other JSON type hits the explicit instanceof check and triggers this MarshalException. It indicates the JSON value supplied for an int column is neither textual nor numeric.","triggerScenarios":"Calling Int32Type.instance.fromJSONObject(parsed, protocolVersion) where parsed is a Boolean/Map/List (e.g. {\"count\": true}); the instanceof Number check fails and MarshalException is thrown.","commonSituations":"JSON documents with booleans or nested objects in int fields; producers using wrong field types after schema changes; imports of loosely typed documents (Mongo-style) into Cassandra tables.","solutions":["Ensure the JSON field is a number or numeric string before insert","Fix the producer/serializer to emit int fields as JSON numbers","Coerce or reject such documents in an ETL validation step","Catch MarshalException and surface a per-field validation error"],"exampleFix":"// before\n{\"count\": true}\n// after\n{\"count\": 42}","handlingStrategy":"validation","validationCode":"if (!(parsed instanceof Number || parsed instanceof String))\n    throw new IllegalArgumentException(\"Expected an int (number or string), got: \" + parsed.getClass().getSimpleName());","typeGuard":"static boolean isIntJson(Object v) { return v instanceof Number || v instanceof String; }","tryCatchPattern":"try { Int32Type.instance.fromJSONObject(parsed, pv); } catch (MarshalException e) { /* reject record: non-numeric JSON value for int field */ }","preventionTips":["Emit int fields as JSON numbers","Validate payload types against table schema before insert","Reject booleans/objects in numeric fields at ETL boundary","Keep producers and schema in sync with contract tests"],"tags":["cassandra","marshalling","json","int"],"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"}