{"record":{"id":"0ed28e59e044880b","repo":"apache/cassandra","slug":"value-s-is-not-a-valid-blob-representation-s","errorCode":null,"errorMessage":"Value '%s' is not a valid blob representation: %s","messagePattern":"Value '(.+?)' is not a valid blob representation: (.+?)","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/BytesType.java","lineNumber":72,"sourceCode":"        {\n            throw new MarshalException(String.format(\"cannot parse '%s' as hex bytes\", source), e);\n        }\n    }\n\n    @Override\n    public Term fromJSONObject(Object parsed) throws MarshalException\n    {\n        try\n        {\n            String parsedString = (String) parsed;\n            if (!parsedString.startsWith(\"0x\"))\n                throw new MarshalException(String.format(\"String representation of blob is missing 0x prefix: %s\", parsedString));\n\n            return new Constants.Value(BytesType.instance.fromString(parsedString.substring(2)));\n        }\n        catch (ClassCastException | MarshalException exc)\n        {\n            throw new MarshalException(String.format(\"Value '%s' is not a valid blob representation: %s\", parsed, exc.getMessage()));\n        }\n    }\n\n    @Override\n    public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)\n    {\n        return \"\\\"0x\" + ByteBufferUtil.bytesToHex(buffer) + '\"';\n    }\n\n    @Override\n    public boolean isCompatibleWith(AbstractType<?> previous)\n    {\n        // Both asciiType and utf8Type really use bytes comparison and\n        // bytesType validate everything, so it is compatible with the former.\n        return this == previous || previous == AsciiType.instance || previous == UTF8Type.instance;\n    }\n\n    @Override","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/BytesType.java#L54-L90","documentation":"BytesType.fromJSONObject wraps ClassCastException and any nested MarshalException into this generic 'not a valid blob representation' error. It fires when the JSON value is not a String at all (cast fails), or when the string fails 0x-prefix or hex parsing; the original message is appended after the colon.","triggerScenarios":"INSERT INTO t JSON '{\"b\": 123}' (number, not string); extended-JSON object payloads like {\"$binary\": ...}; a string failing hex parse inside fromString (nested 'cannot parse ... as hex bytes' message).","commonSituations":"MongoDB-style extended-JSON binary payloads; JSON serializers that emit numbers or objects for binary columns; schema drift where a former text column is now blob and payloads still send unquoted values.","solutions":["Send a plain 0x-prefixed hex string: {\"b\": \"0x00ff\"}","Convert the value to a hex String in application code before JSON insert","Read the nested message after 'representation:' to find the root cause (prefix vs hex)","Align client serialization so binary columns map to hex strings"],"exampleFix":"// before\nINSERT INTO t JSON '{\"b\": {\"$binary\": \"3q2+7w==\"}}';\n// after\nINSERT INTO t JSON '{\"b\": \"0xdeadbeef\"}';","handlingStrategy":"try-catch","validationCode":"if (parsed == null || !(parsed instanceof String))\n    throw new IllegalArgumentException(\"Blob JSON value must be a string\");","typeGuard":"boolean isBlobString(Object v) { return v instanceof String; }","tryCatchPattern":"try { Term t = bytesType.fromJSONObject(parsed); } catch (MarshalException e) { if (e.getMessage().startsWith(\"Value '\")) { /* inspect nested cause, fix payload type/prefix, retry */ } else throw e; }","preventionTips":["Never use extended-JSON {$binary:...} for Cassandra blobs","Serialize binary as hex strings in client models","Parse the nested cause message for diagnosis","Schema-validate payloads (type + format) before insert"],"tags":["cassandra","marshal","json","blob"],"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"}