{"record":{"id":"1007377aa77f68cb","repo":"apache/flink","slug":"unable-to-deserialize-byte-array-100737","errorCode":null,"errorMessage":"Unable to deserialize byte array.","messagePattern":"Unable to deserialize byte array\\.","errorType":"exception","errorClass":"org.apache.flink.formats.json.JsonParseException","httpStatus":null,"severity":"error","filePath":"flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/JsonToRowDataConverters.java","lineNumber":289,"sourceCode":"            return StringData.fromString(jsonNode.toString());\n        } else {\n            return StringData.fromString(jsonNode.asText());\n        }\n    }\n\n    private BinaryVariant convertToVariant(JsonNode jsonNode) {\n        try {\n            return BinaryVariantInternalBuilder.parseJson(jsonNode.toString(), false);\n        } catch (IOException e) {\n            throw new JsonParseException(\"Unable to deserialize VARIANT value.\", e);\n        }\n    }\n\n    private byte[] convertToBytes(JsonNode jsonNode) {\n        try {\n            return jsonNode.binaryValue();\n        } catch (IOException e) {\n            throw new JsonParseException(\"Unable to deserialize byte array.\", e);\n        }\n    }\n\n    private JsonToRowDataConverter createDecimalConverter(DecimalType decimalType) {\n        final int precision = decimalType.getPrecision();\n        final int scale = decimalType.getScale();\n        return jsonNode -> {\n            BigDecimal bigDecimal;\n            if (jsonNode.isBigDecimal()) {\n                bigDecimal = jsonNode.decimalValue();\n            } else {\n                bigDecimal = new BigDecimal(jsonNode.asText());\n            }\n            return DecimalData.fromBigDecimal(bigDecimal, precision, scale);\n        };\n    }\n\n    private JsonToRowDataConverter createArrayConverter(ArrayType arrayType) {","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/JsonToRowDataConverters.java#L271-L307","documentation":"Thrown by JsonToRowDataConverters.convertToBytes when JsonNode.binaryValue() raises an IOException. binaryValue() only succeeds on textual nodes holding valid Base64 (or binary nodes); any other shape (numbers, objects, malformed Base64 text) fails. The target Flink field is declared BINARY/VARBINARY, so the deserializer tries to Base64-decode the JSON value into a byte array.","triggerScenarios":"A column declared BINARY or VARBINARY in the JSON-format table schema while the corresponding JSON field is a number, object/array, or a string that is not valid Base64 (e.g. \"hello world!!\"). Reached via JsonRowDataDeserializationSchema on any source using format 'json'.","commonSituations":"Schema declared BINARY but upstream sends raw non-Base64 strings; column-type mix-ups when hand-writing DDL against an existing JSON stream; producers that emit binary data hex-encoded instead of Base64.","solutions":["Verify the JSON value for the BINARY column is a Base64-encoded string (e.g. via an online decoder or jq)","If the payload is plain text, change the column type from BINARY/VARBINARY to STRING/VARCHAR in the DDL","If the payload is hex-encoded, pre-process upstream, or deserialize as STRING and convert with hex decoding in a UDF","Add sample-record validation before deploying the schema (consume one message and check field shapes)"],"exampleFix":"// before\n`data` BINARY,   -- JSON field \"data\": \"aGVsbG8=\" ok; \"data\": 123 fails\n\n// after\n`data` STRING    -- when the field carries non-Base64 text","handlingStrategy":"validation","validationCode":"// Verify the JSON field is Base64 text before using BINARY in the DDL\nString s = node.get(\"data\").asText();\ntry { Base64.getDecoder().decode(s); } catch (IllegalArgumentException e) { /* not base64: use STRING or fix upstream */ }","typeGuard":null,"tryCatchPattern":"catch (JsonParseException e) for 'Unable to deserialize byte array' — log the field value, treat as data error; do not retry (deterministic).","preventionTips":["Declare BINARY only when upstream guarantees Base64 strings","Contract-test producer output shapes before schema freeze","Hex-encoded data needs a STRING column plus decode UDF"],"tags":["json","binary","base64","deserialization","schema"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}