apache/cassandra · error · MarshalException

Expected a string representation of an inet value, but got a

Error message

Expected a string representation of an inet value, but got a %s: %s

What it means

InetAddressType.fromJSONObject() expects the parsed JSON value to be a String representation of an inet address and casts it before calling fromString. When the value is not a String (Boolean, Number, Map, List), the cast fails with ClassCastException, which is converted to this MarshalException. Cassandra requires a textual IP representation for inet JSON input.

Source

Thrown at src/java/org/apache/cassandra/db/marshal/InetAddressType.java:85

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

        return decompose(address);
    }

    @Override
    public Term fromJSONObject(Object parsed) throws MarshalException
    {
        try
        {
            return new Constants.Value(InetAddressType.instance.fromString((String) parsed));
        }
        catch (ClassCastException exc)
        {
            throw new MarshalException(String.format(
                    "Expected a string representation of an inet value, but got a %s: %s", parsed.getClass().getSimpleName(), parsed));
        }
    }

    private String toString(InetAddress inet)
    {
        return inet != null ? inet.getHostAddress() : "";
    }

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

    public CQL3Type asCQL3Type()
    {
        return CQL3Type.Native.INET;

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Pass the IP as a JSON string: {"ip": "10.0.0.1"}
  2. Fix the producer to serialize inet fields as strings
  3. Convert non-string values explicitly (String.valueOf) only when semantically valid
  4. Catch MarshalException around fromJSONObject and validate JSON field types before insert

Example fix

// before
{"ip": 3232235777}
// after
{"ip": "192.168.1.1"}
Defensive patterns

Strategy: validation

Validate before calling

if (!(parsed instanceof String))
    throw new IllegalArgumentException("inet JSON value must be a string, got: " + parsed.getClass().getSimpleName());

Type guard

static boolean isInetJson(Object v) { return v instanceof String && isValidInet((String) v); }

Try / catch

try { InetAddressType.instance.fromJSONObject(parsed, pv); } catch (MarshalException e) { /* reject record: inet field must be a string */ }

Prevention

When it happens

Trigger: Calling InetAddressType.instance.fromJSONObject(parsed, protocolVersion) where parsed is a non-String JSON value, e.g. {"ip": 12345} or {"ip": true}; the (String) cast throws ClassCastException caught and rethrown as MarshalException.

Common situations: JSON payloads emitting raw integers/booleans for inet columns; schema mismatches where an int column became inet (or vice versa); hand-written migration scripts feeding wrong JSON types.

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/19fa7710832a87e6. Report an issue: GitHub.