{"record":{"id":"9c1a700782fff0bf","repo":"apache/cassandra","slug":"string-representation-of-blob-is-missing-0x-prefix","errorCode":null,"errorMessage":"String representation of blob is missing 0x prefix: %s","messagePattern":"String representation of blob is missing 0x prefix: (.+?)","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/BytesType.java","lineNumber":66,"sourceCode":"    {\n        try\n        {\n            return ByteBuffer.wrap(Hex.hexToBytes(source));\n        }\n        catch (NumberFormatException e)\n        {\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    {","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/BytesType.java#L48-L84","documentation":"BytesType.fromJSONObject throws this when a JSON string value for a blob column does not start with the required '0x' prefix. JSON blob representations must be hex strings prefixed with 0x. Note the outer catch re-wraps MarshalExceptions, so this message may appear nested inside the 'not a valid blob representation' message.","triggerScenarios":"INSERT INTO t JSON '{\"b\": \"deadbeef\"}' (missing 0x); fromJson() with a plain hex string lacking 0x; JSON payloads containing base64-encoded blobs instead of hex.","commonSituations":"Client libraries that base64-encode binary by default (common in JSON ecosystems); hand-written JSON forgetting the prefix; docs/tooling showing bare hex without 0x.","solutions":["Prefix the hex string with 0x: {\"b\": \"0xdeadbeef\"}","Hex-encode binary data (not base64) and add the 0x prefix in the client","Convert base64 payloads to hex before JSON insert","Validate JSON blob fields for the 0x prefix before sending"],"exampleFix":"// before\nINSERT INTO t JSON '{\"b\": \"deadbeef\"}';\n// after\nINSERT INTO t JSON '{\"b\": \"0xdeadbeef\"}';","handlingStrategy":"validation","validationCode":"if (!(v instanceof String) || !((String) v).startsWith(\"0x\"))\n    throw new IllegalArgumentException(\"Blob JSON value must be 0x-prefixed hex string\");","typeGuard":"boolean isBlobJson(Object v) { return v instanceof String && ((String) v).startsWith(\"0x\") && ((String) v).length() % 2 == 0; }","tryCatchPattern":"try { Term t = bytesType.fromJSONObject(parsed); } catch (MarshalException e) { if (e.getMessage().contains(\"missing 0x prefix\")) { /* prepend 0x and retry */ } else throw e; }","preventionTips":["Standardize a blob-encoding helper (hex + 0x prefix) in client libs","Convert base64 to hex at the API boundary","Validate JSON blob fields for the 0x prefix before send","Document blob JSON format in API contracts"],"tags":["cassandra","marshal","json","blob"],"backgroundTag":"invalid-argument-format","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"}