You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2018/03/13 18:34:26 UTC

[incubator-pulsar] branch master updated: add byte array to default pulsar functions serde (#1372)

This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 2f6de57  add byte array to default pulsar functions serde (#1372)
2f6de57 is described below

commit 2f6de5746b644b548cc4e6e0eb4d48f26e901809
Author: Luc Perkins <lu...@gmail.com>
AuthorDate: Tue Mar 13 11:34:24 2018 -0700

    add byte array to default pulsar functions serde (#1372)
---
 .../org/apache/pulsar/functions/api/utils/DefaultSerDe.java    | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/pulsar-functions/api-java/src/main/java/org/apache/pulsar/functions/api/utils/DefaultSerDe.java b/pulsar-functions/api-java/src/main/java/org/apache/pulsar/functions/api/utils/DefaultSerDe.java
index 30a740e..88e3f60 100644
--- a/pulsar-functions/api-java/src/main/java/org/apache/pulsar/functions/api/utils/DefaultSerDe.java
+++ b/pulsar-functions/api-java/src/main/java/org/apache/pulsar/functions/api/utils/DefaultSerDe.java
@@ -32,6 +32,7 @@ import java.util.Set;
 public class DefaultSerDe implements SerDe<Object> {
 
     private static final Set<Class> supportedInputTypes = new HashSet<>(Arrays.asList(
+            byte[].class,
             Integer.class,
             Double.class,
             Long.class,
@@ -49,7 +50,10 @@ public class DefaultSerDe implements SerDe<Object> {
     @Override
     public Object deserialize(byte[] input) {
         String data = new String(input, StandardCharsets.UTF_8);
-        if (type.equals(Integer.class)) {
+
+        if (type.equals(byte[].class)) {
+            return input;
+        } else if (type.equals(Integer.class)) {
             return Integer.valueOf(data);
         } else if (type.equals(Double.class)) {
             return Double.valueOf(data);
@@ -70,7 +74,9 @@ public class DefaultSerDe implements SerDe<Object> {
 
     @Override
     public byte[] serialize(Object input) {
-        if (type.equals(Integer.class)) {
+        if (type.equals(byte[].class)) {
+            return (byte[]) input;
+        } else if (type.equals(Integer.class)) {
             return ((Integer) input).toString().getBytes(StandardCharsets.UTF_8);
         } else if (type.equals(Double.class)) {
             return ((Double) input).toString().getBytes(StandardCharsets.UTF_8);

-- 
To stop receiving notification emails like this one, please contact
mmerli@apache.org.