Given a class like this
public class Message<T> implements Serializable {
final String correlationId;
final LocalDateTime timestamp;
final T payload
}
How to implement a custom Kafka deserializer that can handle the nested generic type?
Serialization should be pretty straight forward, as the type information will be available.
But how to handle not having the type information when deserialising?
p.s: I am using jackson to do the serialization / deserialization.
solved by getting jackson to include the type info when serializing.
public class Message<T> implements Serializable {
final String correlationId;
final LocalDateTime timestamp;
@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="@class")
final T payload
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With