{"record":{"id":"1132caf8e02be1d6","repo":"apache/cassandra","slug":"expected-a-list-but-got-a-s-s","errorCode":null,"errorMessage":"Expected a list, but got a %s: %s","messagePattern":"Expected a list, but got a (.+?): (.+?)","errorType":"exception","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/ListType.java","lineNumber":241,"sourceCode":"    }\n\n    public List<byte[]> serializedValuesAsByteArrays(Iterator<Cell<?>> cells)\n    {\n        assert isMultiCell;\n        List<byte[]> bbs = new ArrayList<>();\n        while (cells.hasNext())\n            bbs.add(cells.next().valueAsArray());\n        return bbs;\n    }\n\n    @Override\n    public Term fromJSONObject(Object parsed) throws MarshalException\n    {\n        if (parsed instanceof String)\n            parsed = JsonUtils.decodeJson((String) parsed);\n\n        if (!(parsed instanceof List))\n            throw new MarshalException(String.format(\n                    \"Expected a list, but got a %s: %s\", parsed.getClass().getSimpleName(), parsed));\n\n        List<?> list = (List<?>) parsed;\n        List<Term> terms = new ArrayList<>(list.size());\n        for (Object element : list)\n        {\n            if (element == null)\n                throw new MarshalException(\"Invalid null element in list\");\n            terms.add(elements.fromJSONObject(element));\n        }\n\n        return new MultiElements.DelayedValue(this, terms);\n    }\n\n    public ByteBuffer getSliceFromSerialized(ByteBuffer collection, ByteBuffer from, ByteBuffer to)\n    {\n        // We don't support slicing on lists so we don't need that function\n        throw new UnsupportedOperationException();","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/ListType.java#L223-L259","documentation":"ListType.fromJSONObject converts a parsed JSON value into a list Term. The JSON value must be a JSON array (or a string that decodes to one); if it is any other JSON type, a MarshalException is thrown naming the actual type received.","triggerScenarios":"Using fromJson()/JSON INSERT with a list column whose JSON value is an object, string (not JSON-encoded array), number, or boolean.","commonSituations":"Clients send {\"tags\": {\"a\":1}} instead of an array; a scalar string like \"a,b,c\" is sent without JSON array encoding; producer/consumer schema drift on list columns.","solutions":["Send a proper JSON array for list columns, e.g. {\"tags\": [\"a\",\"b\"]}.","If sending a string, make it a JSON-encoded array string: \"[\\\"a\\\",\\\"b\\\"]\".","Validate payload shape client-side against the table schema before submitting."],"exampleFix":"// before\n{\"tags\": \"a,b,c\"}\n// after\n{\"tags\": [\"a\", \"b\", \"c\"]}","handlingStrategy":"type-guard","validationCode":"if (!(value instanceof List)) throw new IllegalArgumentException(\"list column expects a JSON array, got: \" + (value == null ? \"null\" : value.getClass().getSimpleName()));","typeGuard":"boolean isJsonArray(Object o) { return o instanceof List; }","tryCatchPattern":"try { term = listType.fromJSONObject(parsed); } catch (MarshalException e) { throw new BadRequestException(\"Invalid list value: \" + e.getMessage()); }","preventionTips":["Always send JSON arrays for list columns.","If using string-encoded JSON, ensure the string itself is a valid JSON array.","Add contract tests verifying payload shape against the table schema."],"tags":["json","list","type-mismatch","marshal"],"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"}