Skip to content

Commit

Permalink
Add a specific codec for byte arrays.
Browse files Browse the repository at this point in the history
Initially, it relied on the JSON codec (encoding the byte arrays using base 64). This was breaking the compatibility with other libraries.

Fix #28029.

(cherry picked from commit 4a2546e)
  • Loading branch information
cescoffier authored and gsmet committed Sep 19, 2022
1 parent 31f47f0 commit e1e2f07
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public static <T> Codec<T> getDefaultCodecFor(Class<T> clazz) {
if (clazz.equals(String.class)) {
return (Codec<T>) StringCodec.INSTANCE;
}
if (clazz.equals(byte[].class)) {
return (Codec<T>) ByteArrayCodec.INSTANCE;
}
// JSON by default
return new JsonCodec<>(clazz);
}
Expand Down Expand Up @@ -114,4 +117,23 @@ public Integer decode(byte[] item) {
}
}

public static class ByteArrayCodec implements Codec<byte[]> {

public static ByteArrayCodec INSTANCE = new ByteArrayCodec();

private ByteArrayCodec() {
// Avoid direct instantiation;
}

@Override
public byte[] encode(byte[] item) {
return item;
}

@Override
public byte[] decode(byte[] item) {
return item;
}
}

}

0 comments on commit e1e2f07

Please sign in to comment.