You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2023/03/28 10:09:51 UTC

[GitHub] [pulsar] jak78 added a comment to the discussion: The pulsar client generics have an exception

GitHub user jak78 added a comment to the discussion: The pulsar client generics have an exception

Hi @livk-cloud! 
Because of the Java compiler's [generics type erasure](https://www.baeldung.com/java-type-erasure), the type information of the `data` field of the `PulsarMessage` class is lost at compile time.
But the Pulsar client needs to know the type of the `data` field of the `PulsarMessage` class. This happens at runtime after the code is compiled.
Because of the type erasure, the Pulsar client is unable to get the type.
To solve this problem, you can create classes with no generic type:

```java
public static class StringPulsarMessage extends PulsarMessage<String> {
    }

SchemaDefinition<StringPulsarMessage> schemaDefinition = SchemaDefinition.<StringPulsarMessage>builder()
                    .withPojo(StringPulsarMessage.class)
                    .build();
```

Please let me know if this works for you.

GitHub link: https://github.com/apache/pulsar/discussions/19946#discussioncomment-5451908

----
This is an automatically sent email for commits@pulsar.apache.org.
To unsubscribe, please send an email to: commits-unsubscribe@pulsar.apache.org