|
15 | 15 | */
|
16 | 16 | package org.springframework.modulith.events.kafka;
|
17 | 17 |
|
| 18 | +import org.springframework.beans.factory.ObjectProvider; |
18 | 19 | import org.springframework.boot.autoconfigure.AutoConfiguration;
|
19 |
| -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; |
| 20 | +import org.springframework.boot.autoconfigure.AutoConfigureBefore; |
20 | 21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
21 | 22 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
22 | 23 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
| 24 | +import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration; |
23 | 25 | import org.springframework.context.annotation.Bean;
|
24 | 26 | import org.springframework.context.annotation.PropertySource;
|
25 | 27 | import org.springframework.kafka.support.converter.ByteArrayJsonMessageConverter;
|
26 |
| -import org.springframework.kafka.support.converter.JsonMessageConverter; |
| 28 | +import org.springframework.kafka.support.converter.RecordMessageConverter; |
27 | 29 |
|
28 | 30 | import com.fasterxml.jackson.databind.ObjectMapper;
|
29 | 31 |
|
|
34 | 36 | * @since 1.1
|
35 | 37 | */
|
36 | 38 | @AutoConfiguration
|
| 39 | +@AutoConfigureBefore(KafkaAutoConfiguration.class) |
37 | 40 | @ConditionalOnClass(ObjectMapper.class)
|
38 | 41 | @ConditionalOnProperty(name = "spring.modulith.events.kafka.enable-json", havingValue = "true", matchIfMissing = true)
|
39 | 42 | @PropertySource("classpath:kafka-json.properties")
|
40 | 43 | class KafkaJacksonConfiguration {
|
41 | 44 |
|
42 | 45 | @Bean
|
43 |
| - @ConditionalOnBean(ObjectMapper.class) |
44 |
| - @ConditionalOnMissingBean(JsonMessageConverter.class) |
45 |
| - ByteArrayJsonMessageConverter jsonMessageConverter(ObjectMapper mapper) { |
46 |
| - return new ByteArrayJsonMessageConverter(mapper); |
| 46 | + @ConditionalOnMissingBean(RecordMessageConverter.class) |
| 47 | + ByteArrayJsonMessageConverter jsonMessageConverter(ObjectProvider<ObjectMapper> mapper) { |
| 48 | + return new ByteArrayJsonMessageConverter(mapper.getIfUnique(() -> new ObjectMapper())); |
47 | 49 | }
|
48 | 50 | }
|
0 commit comments