-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Expected Behavior
End-user should be free from finding the way to propagate configuration properties to their custom (De)Serializier
when they configure it programmatically.
The general idea for the target solution is to call (De)Serializer.configure()
directly in the DefaultKafkaProducerFactory
or DefaultKafkaConsumerFactory
when respective setter is used for external (De)Serializier
.
Such a behavior of those setters must be mentioned in their JavaDocs.
Out-of-the-box (De)Serializier
(e.g. JsonSerializer
) must be guarded with some state like initialized
to not call a configure()
if that has been called externally, e.g. in projects which don't have this fix yet.
Another consistency matter is about to not call configure()
if some setters of that (De)Serializer
has been called: or setters configuration, or via properties, but not both.
Current Behavior
We have to call configure()
explicitly in the factory customizer before setting (de)serializer into that factory back:
public void customize(DefaultKafkaProducerFactory<?, ?> producerFactory) {
JsonSerializer<Object> jsonSerializer = new JsonSerializer<>(objectMapper());
jsonSerializer.configure(producerFactory.getConfigurationProperties(), false);
producerFactory.setValueSerializer((JsonSerializer) jsonSerializer);
}
Context
More info in this SO thread: https://stackoverflow.com/questions/68472258/spring-json-type-mapping-property-ignored-when-specifying-a-custom-objectmapper