Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,11 @@ public T getValue() {
return schema.decode(getData(), schemaVersion);
}
} else {
return schema.decode(getData());
if (getData().length == 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@congbobo184

I think the fix here is a bit problematic. because an application can produce a zero-length bytes array. Can we find a way to differentiate a zero-length bytes payload from a null payload?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should use metadata to store the null payload.

return null;
} else {
return schema.decode(getData());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.pulsar.client.api.Schema;
import org.apache.pulsar.client.api.schema.SchemaDefinition;
import org.apache.pulsar.client.impl.schema.AvroSchema;
import org.apache.pulsar.client.impl.schema.BooleanSchema;
import org.apache.pulsar.client.impl.schema.JSONSchema;
import org.apache.pulsar.client.impl.schema.SchemaTestUtils;
import org.apache.pulsar.client.impl.schema.generic.MultiVersionSchemaInfoProvider;
Expand Down Expand Up @@ -398,4 +399,19 @@ public void testSeparatedAVROJSONVersionGetProducerDataAssigned() {
KeyValueEncodingType.valueOf(keyValueSchema.getSchemaInfo().getProperties().get("kv.encoding.type")),
KeyValueEncodingType.SEPARATED);
}

@Test
public void testTypedSchemaGetNullValue() {

byte[] encodeBytes = new byte[0];
MessageMetadata.Builder builder = MessageMetadata.newBuilder()
.setProducerName("getNullValue");
ByteString byteString = ByteString.copyFrom(new byte[0]);
builder.setSchemaVersion(byteString);
builder.setPartitionKey(Base64.getEncoder().encodeToString(encodeBytes));
builder.setPartitionKeyB64Encoded(true);
MessageImpl<Boolean> msg = MessageImpl.create(
builder, ByteBuffer.wrap(encodeBytes), BooleanSchema.of());
assertNull(msg.getValue());
}
}