{"record":{"id":"fbc2637bfbc7d23f","repo":"apache/flink","slug":"unable-to-deserialize-variant-value","errorCode":null,"errorMessage":"Unable to deserialize VARIANT value.","messagePattern":"Unable to deserialize VARIANT value\\.","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":281,"sourceCode":"        LocalDate localDate = parsedTimestampWithLocalZone.query(TemporalQueries.localDate());\n\n        return TimestampData.fromInstant(\n                LocalDateTime.of(localDate, localTime).toInstant(ZoneOffset.UTC));\n    }\n\n    private StringData convertToString(JsonNode jsonNode) {\n        if (jsonNode.isContainerNode()) {\n            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();","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/JsonToRowDataConverters.java#L263-L299","documentation":"Thrown by JsonToRowDataConverters.convertToVariant when a JSON node declared as VARIANT in the table schema cannot be re-parsed into a BinaryVariant via BinaryVariantInternalBuilder.parseJson. The deserializer runs the node's textual form through the VARIANT parser, and any IOException from that parser is wrapped into this JsonParseException. It means the incoming JSON value is not representable as a VARIANT even though it arrived as valid JSON.","triggerScenarios":"A table column declared as VARIANT where the JSON value at that position fails BinaryVariantInternalBuilder.parseJson (e.g. a value form the variant parser rejects, such as an unsupported literal or a node whose string form the parser cannot consume). Reached through JsonRowDataDeserializationSchema / the 'json' format on a Kafka source whose derived schema contains VARIANT.","commonSituations":"CDC or upstream producers emitting values that do not round-trip through the VARIANT parser; schema evolution marking a column VARIANT when the payload is not variant-compatible; version mismatches between the VARIANT parser and the JSON payload.","solutions":["Inspect the failing JSON record (log the raw message) and identify the field declared VARIANT that fails to parse","If the column is not truly a VARIANT, change its type in the DDL to the concrete JSON-compatible type (STRING, ROW, ARRAY, MAP)","If the data is correct but occasional records are bad, set 'json.ignore-parse-errors' = true to skip them (only for Canal/Debezium/JSON formats that support it)","Upgrade flink-formats-json / flink-table to a version whose VARIANT parser accepts the value, if this is a parser bug"],"exampleFix":"// before\nCREATE TABLE t (v VARIANT) WITH ('connector'='kafka', 'format'='json', ...);\n\n// after: use STRING if the payload is arbitrary JSON text\nCREATE TABLE t (v STRING) WITH ('connector'='kafka', 'format'='json', ...);","handlingStrategy":"validation","validationCode":"// Before assigning VARIANT, check the value parses as JSON the variant parser accepts\nObjectNode node = mapper.readValue(json, ObjectNode.class);\ntry { BinaryVariantInternalBuilder.parseJson(node.toString(), false); }\ncatch (IOException e) { /* route record to quarantine, do not send to VARIANT column */ }","typeGuard":null,"tryCatchPattern":"catch (JsonParseException e) when 'Unable to deserialize VARIANT' — inspect cause IOException; quarantine the record and keep the source running rather than retrying the same bytes.","preventionTips":["Validate sample messages against a VARIANT column before deploying","Prefer STRING for arbitrary JSON payloads","Pin producer and Flink format versions together"],"tags":["json","variant","deserialization","flink-json"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}