gpt4 book ai didi

java - 如何在 Spring Kafka 中以编程方式设置 Jsonserializer Type Value 方法

转载 作者:行者123 更新时间:2023-12-01 14:31:36 30 4
gpt4 key购买 nike

所以我无法仅使用 yaml 为 JsonSerializer 配置 JavaType 方法。尚不确定原因,但与此同时我该如何以编程方式设置它?

我在文档中看到了它的代码,但这段代码究竟需要在哪里运行?

Spring Kafka: JsonDeserializer doesn't pick up TRUSTED_PACKAGE config

到目前为止,这是我尝试过的。 Kafka Spring Deserialzer returnType static method never called

PS 我使用的是 Spring Boot 2.1.8,所以现在不能轻易地使用只有属性的新方法。

最佳答案

要在旧的 Boot 版本中获得此功能,您需要将代码从 2.5 JsonDeserializer 复制到自定义反序列化器中 - typeFunction 是在 2.5 中添加的。

以编程方式创建反序列化器时,必须将其直接添加到消费者工厂。参见 the documentation .

For more complex or particular cases, the KafkaConsumer (and, therefore, KafkaProducer) provides overloaded constructors to accept Serializer and Deserializer instances for keys and values, respectively.

When you use this API, the DefaultKafkaProducerFactory and DefaultKafkaConsumerFactory also provide properties (through constructors or setter methods) to inject custom Serializer and Deserializer instances into the target Producer or Consumer. Also, you can pass in Supplier or Supplier instances through constructors - these Supplier s are called on creation of each Producer or Consumer.

创建一个 DefaultKafkaConsumerFactory @Bean(覆盖 Boot 的默认值)。

关于java - 如何在 Spring Kafka 中以编程方式设置 Jsonserializer Type Value 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63275816/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com