{"record":{"id":"45d88c46a7ec3ae4","repo":"apache/cassandra","slug":"expected-a-bigint-value-but-got-a-s-s","errorCode":null,"errorMessage":"Expected a bigint value, but got a %s: %s","messagePattern":"Expected a bigint value, but got a (.+?): (.+?)","errorType":"exception","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/LongType.java","lineNumber":127,"sourceCode":"        catch (Exception e)\n        {\n            throw new MarshalException(String.format(\"Unable to make long from '%s'\", source), e);\n        }\n\n        return decompose(longType);\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 || parsedNumber instanceof Long))\n                throw new MarshalException(String.format(\"Expected a bigint value, but got a %s: %s\", parsed.getClass().getSimpleName(), parsed));\n\n            return new Constants.Value(getSerializer().serialize(parsedNumber.longValue()));\n        }\n        catch (ClassCastException exc)\n        {\n            throw new MarshalException(String.format(\n                    \"Expected a bigint 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    @Override\n    public boolean isValueCompatibleWithInternal(AbstractType<?> otherType)","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/LongType.java#L109-L145","documentation":"LongType.fromJSONObject accepts a JSON string (parsed via fromString) or a JSON integer for a bigint column. If the value is a Number but not an Integer or Long (e.g. Double, Float, BigInteger), it cannot be safely narrowed to a long, so a MarshalException is thrown.","triggerScenarios":"Using fromJson()/JSON INSERT with a bigint column whose JSON value is a floating-point number (e.g. 1.5) or an oversized integer that the JSON parser decoded as Double/BigInteger rather than Integer/Long.","commonSituations":"JavaScript clients serializing all numbers as doubles; JSON payloads with decimal values for count columns; very large integers from other languages exceeding double precision.","solutions":["Send the value as a JSON integer without a decimal point, or as a quoted string of digits.","Round/convert the value to an integer client-side before sending.","If fractional values are legitimate, use a double or decimal column type instead of bigint."],"exampleFix":"// before\n{\"count\": 1.5}\n// after\n{\"count\": \"1\"}  // or {\"count\": 1}","handlingStrategy":"type-guard","validationCode":"boolean ok = value instanceof String || value instanceof Integer || value instanceof Long;\nif (!ok) throw new IllegalArgumentException(\"bigint expects a JSON integer or digit string, got: \" + value.getClass().getSimpleName());","typeGuard":"boolean isJsonBigint(Object o) { return o instanceof Integer || o instanceof Long || (o instanceof String && isValidLong((String) o)); }","tryCatchPattern":"try { return LongType.instance.fromJSONObject(parsed); } catch (MarshalException e) { throw new BadRequestException(\"bigint field must be an integer: \" + e.getMessage()); }","preventionTips":["Avoid floating-point JSON values for bigint columns.","Use string encoding for large integers to preserve precision across languages.","Configure JS clients (or use BigInt serialization) so whole numbers stay integers in JSON."],"tags":["bigint","json","type-mismatch","number-format"],"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"}