apache/cassandra · error · MarshalException

Expected an int value, but got a %s: %s

Error message

Expected an int value, but got a %s: %s

What it means

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.

Source

Thrown at src/java/org/apache/cassandra/db/marshal/Int32Type.java:115

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

        return decompose(int32Type);
    }

    @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))
                throw new MarshalException(String.format("Expected an int value, but got a %s: %s", parsed.getClass().getSimpleName(), parsed));

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

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

    public CQL3Type asCQL3Type()
    {

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Ensure the JSON field is a number or numeric string before insert
  2. Fix the producer/serializer to emit int fields as JSON numbers
  3. Coerce or reject such documents in an ETL validation step
  4. Catch MarshalException and surface a per-field validation error

Example fix

// before
{"count": true}
// after
{"count": 42}
Defensive patterns

Strategy: validation

Validate before calling

if (!(parsed instanceof Number || parsed instanceof String))
    throw new IllegalArgumentException("Expected an int (number or string), got: " + parsed.getClass().getSimpleName());

Type guard

static boolean isIntJson(Object v) { return v instanceof Number || v instanceof String; }

Try / catch

try { Int32Type.instance.fromJSONObject(parsed, pv); } catch (MarshalException e) { /* reject record: non-numeric JSON value for int field */ }

Prevention

When it happens

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

Common situations: 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.

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/8906328759370f23. Report an issue: GitHub.