apache/cassandra · error · MarshalException

Expected a bigint value, but got a %s: %s

Error message

Expected a bigint value, but got a %s: %s

What it means

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.

Source

Thrown at src/java/org/apache/cassandra/db/marshal/LongType.java:127

        catch (Exception e)
        {
            throw new MarshalException(String.format("Unable to make long from '%s'", source), e);
        }

        return decompose(longType);
    }

    @Override
    public Term fromJSONObject(Object parsed) throws MarshalException
    {
        try
        {
            if (parsed instanceof String)
                return new Constants.Value(fromString((String) parsed));

            Number parsedNumber = (Number) parsed;
            if (!(parsedNumber instanceof Integer || parsedNumber instanceof Long))
                throw new MarshalException(String.format("Expected a bigint value, but got a %s: %s", parsed.getClass().getSimpleName(), parsed));

            return new Constants.Value(getSerializer().serialize(parsedNumber.longValue()));
        }
        catch (ClassCastException exc)
        {
            throw new MarshalException(String.format(
                    "Expected a bigint value, but got a %s: %s", parsed.getClass().getSimpleName(), parsed));
        }
    }

    @Override
    public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)
    {
        return Objects.toString(getSerializer().deserialize(buffer), "\"\"");
    }

    @Override
    public boolean isValueCompatibleWithInternal(AbstractType<?> otherType)

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Send the value as a JSON integer without a decimal point, or as a quoted string of digits.
  2. Round/convert the value to an integer client-side before sending.
  3. If fractional values are legitimate, use a double or decimal column type instead of bigint.

Example fix

// before
{"count": 1.5}
// after
{"count": "1"}  // or {"count": 1}
Defensive patterns

Strategy: type-guard

Validate before calling

boolean ok = value instanceof String || value instanceof Integer || value instanceof Long;
if (!ok) throw new IllegalArgumentException("bigint expects a JSON integer or digit string, got: " + value.getClass().getSimpleName());

Type guard

boolean isJsonBigint(Object o) { return o instanceof Integer || o instanceof Long || (o instanceof String && isValidLong((String) o)); }

Try / catch

try { return LongType.instance.fromJSONObject(parsed); } catch (MarshalException e) { throw new BadRequestException("bigint field must be an integer: " + e.getMessage()); }

Prevention

When it happens

Trigger: 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.

Common situations: JavaScript clients serializing all numbers as doubles; JSON payloads with decimal values for count columns; very large integers from other languages exceeding double precision.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/45d88c46a7ec3ae4. Report an issue: GitHub.