Search code examples
javaspringscaladeserializationspring-kafka

How do you disable trusted.packages check for Spring-Kafka JsonDeserializer?


I have legacy Spring-Scala project. I have added new event type to one of the topics and now consumers throw exceptions

Caused by: java.lang.IllegalArgumentException: The class '...' is not in the trusted packages: [java.util, java.lang, ...].

It seems that a few classes are always added by Spring. I want to disable this feature but it seems that list of classes must be empty for the code to ignore it. But I don't see how that list would ever be empty if some java packages are added by Spring itself. Any suggestions?


Solution

  • I got this. There is a method called .addTrustedPackages and it handles "*" argument as one that clears the internal trustedPackages list. Neat design... >.<

    So the following code works

    val deserializer = new JsonDeserializer[...]()
    deserializer.addTrustedPackages("*")