{"record":{"id":"7cdb98396ae02904","repo":"apache/cassandra","slug":"expected-a-s-string-but-got-a-s-s","errorCode":null,"errorMessage":"Expected a %s string, but got a %s: %s","messagePattern":"Expected a (.+?) string, but got a (.+?): (.+?)","errorType":"exception","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/PseudoUtf8Type.java","lineNumber":52,"sourceCode":"    PseudoUtf8Type() {super(ComparisonType.CUSTOM);} // singleton\n\n    abstract String describe();\n\n    public ByteBuffer fromString(String source)\n    {\n        return decompose(source);\n    }\n\n    @Override\n    public Term fromJSONObject(Object parsed) throws MarshalException\n    {\n        try\n        {\n            return new Constants.Value(fromString((String) parsed));\n        }\n        catch (ClassCastException exc)\n        {\n            throw new MarshalException(String.format(\n                    \"Expected a %s string, but got a %s: %s\", describe(), parsed.getClass().getSimpleName(), parsed));\n        }\n    }\n\n    @Override\n    public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)\n    {\n        try\n        {\n            return '\"' + JsonUtils.quoteAsJsonString(ByteBufferUtil.string(buffer, StandardCharsets.UTF_8)) + '\"';\n        }\n        catch (CharacterCodingException exc)\n        {\n            throw new AssertionError(describe() + \" value contained non-utf8 characters: \", exc);\n        }\n    }\n\n    @Override","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/PseudoUtf8Type.java#L34-L70","documentation":"PseudoUtf8Type.fromJSONObject expects a JSON string for this UTF8-like type (used for token/timestamp-as-string pseudo types; describe() names the expected kind). Non-string JSON values throw ClassCastException, rethrown as this MarshalException including the type description and offending value.","triggerScenarios":"fromJson()/INSERT JSON where a column of a PseudoUtf8Type (e.g. token or timestamp-as-string) is given a number, boolean, null, array or object instead of a string.","commonSituations":"Generating JSON where the token value is numeric; nulling out the field when the source value is missing; client model uses a non-string type for these pseudo columns.","solutions":["Wrap the value as a JSON string before sending (String.valueOf on the client).","Add a client-side check that the field is a string before serializing the payload.","Avoid writing null into these columns; omit the field or use a sentinel string per your data model."],"exampleFix":"// before\n{\"token\": 12345}\n// after\n{\"token\": \"12345\"}","handlingStrategy":"type-guard","validationCode":"if (!(parsed instanceof String)) throw new IllegalArgumentException(describe() + \" must be a string\");","typeGuard":"boolean isUtf8String(Object v) { return v instanceof String; }","tryCatchPattern":"try { return type.fromJSONObject(parsed); } catch (MarshalException e) { /* handle non-string JSON */ }","preventionTips":["Always JSON-quote values for utf8/token/timestamp-string columns","Avoid nulling pseudo-utf8 fields; omit or use empty string per data model","Add client-side serializer tests for these column types"],"tags":["cassandra","json","utf8","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}