-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Deserialization of event without data produces null. #540
Comments
Work-around:
|
Not according to that class' contract [emphasis mine]: ——
—— |
The Kafka contract does not apply here. The bug is simply that no CloudEvent is returned, even though the record clearly contains a CloudEvent. If this was not the case, I could not work-around the bug by putting some dummy data into the event. I believe it is likely to do with the code that auto-detects whether binary or structured deserialization was used. |
Example of record that fail:
|
That IS interesting. For sure, @alexec. Especially given this precondition…
Let me ask you this…
import io.cloudevents.CloudEvent;
import io.cloudevents.core.message.Encoding;
import io.cloudevents.core.message.MessageReader;
import io.cloudevents.core.test.Data;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class CloudEventIssue540ReproducerTest {
private final CloudEvent eventHasNoDataField = CloudEventBuilder.v1()
.withId(…)
.withType(…)
.withSource(…)
.withoutData() // (0) An event that does not have a data field
.withSubject(…)
.build();
@Test
public void ceIssue540DeserializerShouldWork() {
String topic = "test";
CloudEventMessageDeserializer deserializer = new CloudEventMessageDeserializer();
ProducerRecord<Void, byte[]> inRecord = KafkaMessageFactory.createWriter(topic)
.writeBinary(eventHasNoDataField); // (1) "…serialize an event that does not have a data field…" — @alexec
MessageReader outMessage = deserializer
.deserialize(topic, inRecord.headers(), inRecord.value()); // (2) "…then try to deserialize…" — @alexec
assertThat(eventHasNoDataField.getData())
.isNotNull(); // (3) "…you get a null value…" — @alexec
assertThat(outMessage.toEvent())
.isNotNull(); // (4) "…no CloudEvent is returned…" — @alexec
assertThat(outMessage.toEvent())
.isEqualTo(eventHasNoDataField );
assertThat(outMessage.toEvent().getData())
.isNotNull(); // (5) "…you get a null value…" — @alexec
}
} TIA. |
If you serialize an event that does not have a data field using
CloudEventSerializer
using default setting, and then try to deserialize usingCloudEventDeserializer
you get a null value.This is a bug surely.
The text was updated successfully, but these errors were encountered: