kkonstantine commented on a change in pull request #9950: URL: https://github.com/apache/kafka/pull/9950#discussion_r578823263
########## File path: connect/transforms/src/main/java/org/apache/kafka/connect/transforms/Cast.java ########## @@ -364,11 +365,24 @@ private static String castToString(Object value) { if (value instanceof java.util.Date) { java.util.Date dateValue = (java.util.Date) value; return Values.dateFormatFor(dateValue).format(dateValue); + } else if (value instanceof ByteBuffer) { + ByteBuffer byteBuffer = (ByteBuffer) value; + return castByteArrayToString(byteBuffer.array()); Review comment: formally we should almost always check that a `ByteBuffer` is indeed backed by an array with `hasArray` or this part my throw exceptions now: https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html#array-- ########## File path: connect/transforms/src/main/java/org/apache/kafka/connect/transforms/Cast.java ########## @@ -364,11 +365,24 @@ private static String castToString(Object value) { if (value instanceof java.util.Date) { java.util.Date dateValue = (java.util.Date) value; return Values.dateFormatFor(dateValue).format(dateValue); + } else if (value instanceof ByteBuffer) { + ByteBuffer byteBuffer = (ByteBuffer) value; + return castByteArrayToString(byteBuffer.array()); + } else if (value instanceof byte[]) { + return castByteArrayToString((byte[]) value); } else { return value.toString(); } } + private static String castByteArrayToString(byte[] array) { + StringBuilder sbuf = new StringBuilder(); + for (byte b : array) { + sbuf.append(String.format("%02X", b)); Review comment: Also, I'm a bit curious. Why are we selecting hex here and not base64 for example? Hex of course is less efficient. https://issues.apache.org/jira/browse/KAFKA-12170 does not mention anything about the rational, so I thought I'd ask. @rhauch wdyt about the representation here? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org