kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jun...@apache.org
Subject kafka git commit: kafka-1797; (addressing Manikumar Reddy's comment) add the serializer/deserializer api to the new java client; patched by Jun Rao; reviewed by Manikumar Reddy and Neha Narkhede
Date Fri, 09 Jan 2015 19:27:05 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk f82518a85 -> a93ef199b


kafka-1797; (addressing Manikumar Reddy's comment) add the serializer/deserializer api to
the new java client; patched by Jun Rao; reviewed by Manikumar Reddy and Neha Narkhede


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/a93ef199
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/a93ef199
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/a93ef199

Branch: refs/heads/trunk
Commit: a93ef199b2375c422e35d82ac7aa3a2fdacc1e74
Parents: f82518a
Author: Jun Rao <junrao@gmail.com>
Authored: Fri Jan 9 11:27:00 2015 -0800
Committer: Jun Rao <junrao@gmail.com>
Committed: Fri Jan 9 11:27:00 2015 -0800

----------------------------------------------------------------------
 .../apache/kafka/common/serialization/StringDeserializer.java   | 5 ++++-
 .../org/apache/kafka/common/serialization/StringSerializer.java | 5 ++++-
 .../apache/kafka/common/serialization/SerializationTest.java    | 4 +++-
 3 files changed, 11 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/a93ef199/clients/src/main/java/org/apache/kafka/common/serialization/StringDeserializer.java
----------------------------------------------------------------------
diff --git a/clients/src/main/java/org/apache/kafka/common/serialization/StringDeserializer.java
b/clients/src/main/java/org/apache/kafka/common/serialization/StringDeserializer.java
index a3b3700..9783ea0 100644
--- a/clients/src/main/java/org/apache/kafka/common/serialization/StringDeserializer.java
+++ b/clients/src/main/java/org/apache/kafka/common/serialization/StringDeserializer.java
@@ -37,7 +37,10 @@ public class StringDeserializer implements Deserializer<String> {
     @Override
     public String deserialize(String topic, byte[] data) {
         try {
-            return new String(data, encoding);
+            if (data == null)
+                return null;
+            else
+                return new String(data, encoding);
         } catch (UnsupportedEncodingException e) {
             throw new SerializationException("Error when deserializing byte[] to string due
to unsupported encoding " + encoding);
         }

http://git-wip-us.apache.org/repos/asf/kafka/blob/a93ef199/clients/src/main/java/org/apache/kafka/common/serialization/StringSerializer.java
----------------------------------------------------------------------
diff --git a/clients/src/main/java/org/apache/kafka/common/serialization/StringSerializer.java
b/clients/src/main/java/org/apache/kafka/common/serialization/StringSerializer.java
index 02db47f..636d905 100644
--- a/clients/src/main/java/org/apache/kafka/common/serialization/StringSerializer.java
+++ b/clients/src/main/java/org/apache/kafka/common/serialization/StringSerializer.java
@@ -37,7 +37,10 @@ public class StringSerializer implements Serializer<String> {
     @Override
     public byte[] serialize(String topic, String data) {
         try {
-            return data.getBytes(encoding);
+            if (data == null)
+                return null;
+            else
+                return data.getBytes(encoding);
         } catch (UnsupportedEncodingException e) {
             throw new SerializationException("Error when serializing string to byte[] due
to unsupported encoding " + encoding);
         }

http://git-wip-us.apache.org/repos/asf/kafka/blob/a93ef199/clients/src/test/java/org/apache/kafka/common/serialization/SerializationTest.java
----------------------------------------------------------------------
diff --git a/clients/src/test/java/org/apache/kafka/common/serialization/SerializationTest.java
b/clients/src/test/java/org/apache/kafka/common/serialization/SerializationTest.java
index d550a31..b6e1497 100644
--- a/clients/src/test/java/org/apache/kafka/common/serialization/SerializationTest.java
+++ b/clients/src/test/java/org/apache/kafka/common/serialization/SerializationTest.java
@@ -48,8 +48,10 @@ public class SerializationTest {
 
             assertEquals("Should get the original string after serialization and deserialization
with encoding " + encoding,
                     str, deserializer.deserialize(mytopic, serializer.serialize(mytopic,
str)));
-        }
 
+            assertEquals("Should support null in serialization and deserialization with encoding
" + encoding,
+                    null, deserializer.deserialize(mytopic, serializer.serialize(mytopic,
null)));
+        }
     }
 
     private SerDeser<String> getStringSerDeser(String encoder) {


Mime
View raw message