{"record":{"id":"94523464fa64bb8d","repo":"apache/seatunnel","slug":"unsupported-convert-value-getclass-to-byte","errorCode":null,"errorMessage":"Unsupported convert ${value.getClass()} to byte[], typeDefine: ${typeDefine}","messagePattern":"Unsupported convert (.+?) to byte\\[\\], typeDefine: (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"seatunnel-api/src/main/java/org/apache/seatunnel/api/table/converter/BasicDataConverter.java","lineNumber":370,"sourceCode":"    default String convertString(LocalTime value) {\n        return value.toString();\n    }\n\n    default String convertString(LocalDateTime value) {\n        return value.toString();\n    }\n\n    default byte[] convertBytes(T typeDefine, Object value) throws UnsupportedOperationException {\n        if (value instanceof byte[]) {\n            return (byte[]) value;\n        }\n        if (value instanceof ByteBuffer) {\n            return convertBytes((ByteBuffer) value);\n        }\n        if (value instanceof String) {\n            return convertBytes(typeDefine, (String) value);\n        }\n        throw new UnsupportedOperationException(\n                \"Unsupported convert \"\n                        + value.getClass()\n                        + \" to byte[], typeDefine: \"\n                        + typeDefine);\n    }\n\n    default byte[] convertBytes(T typeDefine, String value) {\n        return convertBytes(value);\n    }\n\n    default byte[] convertBytes(Object value) throws UnsupportedOperationException {\n        if (value instanceof byte[]) {\n            return (byte[]) value;\n        }\n        if (value instanceof ByteBuffer) {\n            return convertBytes((ByteBuffer) value);\n        }\n        if (value instanceof String) {","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/converter/BasicDataConverter.java#L352-L388","documentation":"The typeDefine-aware convertBytes overload supports byte[], ByteBuffer, and String inputs; anything else triggers this UnsupportedOperationException. The typeDefine gives context about the expected BytesType column. It fires when a value routed to BYTES conversion is none of the three supported classes.","triggerScenarios":"Calling convertBytes(typeDefine, value) — or convert(...) with a BYTES SqlType column — with an Integer, List of Bytes, POJO, InputStream, or other non-byte[]/ByteBuffer/String object.","commonSituations":"Upstream returns a boxed numeric or a protobuf ByteString instead of byte[]; passing a Base64 string where raw bytes were expected (works, since String is handled, but a wrapper object does not); deserialized collections of bytes.","solutions":["Convert the value to byte[] yourself first (e.g. ByteString.toByteArray(), or serialize the POJO with an agreed format).","If the value is a wrapper like protobuf ByteString, call its toByteArray() before conversion.","Override convertBytes in your converter to handle the offending class.","Check the schema: if the data is really an integer or string, use the appropriate SqlType instead of BYTES."],"exampleFix":"// before\nconverter.convertBytes(bytesType, protoByteString);\n// after\nconverter.convertBytes(bytesType, protoByteString.toByteArray());","handlingStrategy":"type-guard","validationCode":"if (!(value instanceof byte[]) && !(value instanceof ByteBuffer) && !(value instanceof String)) {\n    throw new IllegalArgumentException(\"convertBytes expects byte[]/ByteBuffer/String, got \" + value.getClass());\n}","typeGuard":"boolean isBytesConvertible(Object v) {\n    return v instanceof byte[] || v instanceof ByteBuffer || v instanceof String;\n}","tryCatchPattern":"try {\n    return converter.convertBytes(bytesType, value);\n} catch (UnsupportedOperationException e) {\n    LOG.warn(\"Bytes conversion failed for {}: {}\", value.getClass(), e.getMessage());\n    return null;\n}","preventionTips":["Convert wrapper byte containers (ByteString, ByteBuf) to byte[] before conversion.","Use BYTES SqlType only for genuinely binary data.","Agree on encoding when passing Strings that represent bytes (Base64 vs raw).","Unit-test conversions with representative upstream types."],"tags":["type-mismatch","bytes-conversion","seatunnel-api"],"backgroundTag":"type-mismatch","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}