divijvaidya commented on code in PR #13382:
URL: https://github.com/apache/kafka/pull/13382#discussion_r1133507231


##########
clients/src/main/java/org/apache/kafka/common/serialization/BooleanDeserializer.java:
##########
@@ -0,0 +1,27 @@
+package org.apache.kafka.common.serialization;

Review Comment:
   static check `:rat` is failing because we are missing the apache license at 
the top of the file here.
   
   (same for other new files)



##########
clients/src/test/java/org/apache/kafka/common/serialization/SerializationTest.java:
##########
@@ -389,4 +389,29 @@ public void testByteBufferSerializer() {
             assertArrayEquals(bytes, serializer.serialize(topic, 
directBuffer1));
         }
     }
+
+    @Test
+    public void testBooleanSerializer() {
+        byte[] testData = new byte[1];
+        testData[0] = (byte) 1;
+
+        Serde<Boolean> booleanSerde = Serdes.Boolean();
+        assertArrayEquals(testData, booleanSerde.serializer().serialize(topic, 
true));
+    }
+
+    @Test
+    public void testBooleanDeserializer() {
+        byte[] testData = new byte[1];
+        testData[0] = (byte) 1;
+
+        Serde<Boolean> booleanSerde = Serdes.Boolean();
+        assertEquals(true, booleanSerde.deserializer().deserialize(topic, 
testData));
+    }
+
+    @Test
+    public void booleanDeserializerShouldThrowOnNotNullValues() {

Review Comment:
   perhaps rename this to `booleanDeserializerShouldThrowOnEmptyInput` ?



##########
clients/src/test/java/org/apache/kafka/common/serialization/SerializationTest.java:
##########
@@ -389,4 +389,29 @@ public void testByteBufferSerializer() {
             assertArrayEquals(bytes, serializer.serialize(topic, 
directBuffer1));
         }
     }
+
+    @Test

Review Comment:
   perhaps we can use `@ParameterizedTest` here to use this unit test for both 
`true` and `false`. 



##########
clients/src/main/java/org/apache/kafka/common/serialization/BooleanSerializer.java:
##########
@@ -0,0 +1,17 @@
+package org.apache.kafka.common.serialization;
+
+public class BooleanSerializer implements Serializer<Boolean> {
+
+    private static final byte TRUE = 0x01;
+    private static final byte FALSE = 0x00;
+    @Override
+    public byte[] serialize(final String topic, final Boolean data) {
+        if (data == null) {
+            return null;
+        }
+
+        return new byte[] {
+                data ? TRUE : FALSE

Review Comment:
   nit 
   
   indentation



-- 
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.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to