As Spring doc suggests here, you can customize the behaviour of Json(De)Serializer in Kafka with an ObjectMapper
but it does not specify how.
It turns out that Json(De)Serializer
has a constructor which takes an ObjectMapper
as arg, so you can inject the bean like:
@Bean
Deserializer jsonDeserializer(ObjectMapper objectMapper) {
return new JsonDeserializer(objectMapper);
}
as stated here.
Also, if you need to add trusted package, you need to:
ObjectMapper
from context, pass it to the bean of json serializer@Bean
method, add trusted packageAnd the link above also mentions that if you use context properties to get the Json(De)Serializer
, it is generated by Kafka, without being aware of any context.