Skip to content

Commit 8dc1dcd

Browse files
garyrussellartembilan
authored andcommitted
GH-686: Handle tombstones in Json Ser/Deser
Fixes #686 **Cherry-pick to 2.1.x, 2.0.x, 1.3.x**
1 parent a9d22dc commit 8dc1dcd

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Diff for: spring-kafka/src/main/java/org/springframework/kafka/support/serializer/JsonDeserializer.java

+6
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ private void addTargetPackageToTrusted() {
215215

216216
@Override
217217
public T deserialize(String topic, Headers headers, byte[] data) {
218+
if (data == null) {
219+
return null;
220+
}
218221
JavaType javaType = this.typeMapper.toJavaType(headers);
219222
if (javaType == null) {
220223
Assert.state(this.targetType != null, "No type information in headers and no default type provided");
@@ -233,6 +236,9 @@ public T deserialize(String topic, Headers headers, byte[] data) {
233236

234237
@Override
235238
public T deserialize(String topic, byte[] data) {
239+
if (data == null) {
240+
return null;
241+
}
236242
if (this.reader == null) {
237243
this.reader = this.objectMapper.readerFor(this.targetType);
238244
}

Diff for: spring-kafka/src/main/java/org/springframework/kafka/support/serializer/JsonSerializer.java

+6
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ else if (config instanceof String) {
130130

131131
@Override
132132
public byte[] serialize(String topic, Headers headers, T data) {
133+
if (data == null) {
134+
return null;
135+
}
133136
if (this.addTypeInfo && headers != null) {
134137
this.typeMapper.fromJavaType(this.objectMapper.constructType(data.getClass()), headers);
135138
}
@@ -138,6 +141,9 @@ public byte[] serialize(String topic, Headers headers, T data) {
138141

139142
@Override
140143
public byte[] serialize(String topic, T data) {
144+
if (data == null) {
145+
return null;
146+
}
141147
try {
142148
byte[] result = null;
143149
if (data != null) {

0 commit comments

Comments
 (0)