diff --git a/changelog.md b/changelog.md index 396afe1aa..ada34ba9a 100644 --- a/changelog.md +++ b/changelog.md @@ -16,6 +16,7 @@ typeMapper = MyCloudEventTypeMapper() ) ``` +* Fixed problem with spring-boot autoconfiguration in which it previously failed to create a default cloud event converter if no type mapper was specified explicitly. * Updated to Kotlin 1.9.20 ### 0.16.10 (2023-10-21) diff --git a/framework/spring-boot-starter-mongodb/src/main/java/org/occurrent/springboot/mongo/blocking/OccurrentMongoAutoConfiguration.java b/framework/spring-boot-starter-mongodb/src/main/java/org/occurrent/springboot/mongo/blocking/OccurrentMongoAutoConfiguration.java index a7242dcf6..d9ad9e617 100644 --- a/framework/spring-boot-starter-mongodb/src/main/java/org/occurrent/springboot/mongo/blocking/OccurrentMongoAutoConfiguration.java +++ b/framework/spring-boot-starter-mongodb/src/main/java/org/occurrent/springboot/mongo/blocking/OccurrentMongoAutoConfiguration.java @@ -21,6 +21,7 @@ import com.mongodb.ReadConcern; import com.mongodb.TransactionOptions; import com.mongodb.WriteConcern; +import org.jetbrains.annotations.NotNull; import org.occurrent.application.converter.CloudEventConverter; import org.occurrent.application.converter.jackson.JacksonCloudEventConverter; import org.occurrent.application.converter.typemapper.CloudEventTypeMapper; @@ -117,16 +118,22 @@ public SubscriptionModel occurrentCompetingDurableSubscriptionModel(MongoTemplat @Bean @ConditionalOnMissingBean(CloudEventConverter.class) - public CloudEventConverter occurrentCloudEventConverter(Optional objectMapper, OccurrentProperties occurrentProperties, CloudEventTypeMapper cloudEventTypeMapper) { - ObjectMapper mapper = objectMapper.orElseGet(ObjectMapper::new); - return new JacksonCloudEventConverter.Builder(mapper, occurrentProperties.getCloudEventConverter().getCloudEventSource()) - .typeMapper(cloudEventTypeMapper) + public CloudEventConverter occurrentCloudEventConverter(Optional objectMapper, OccurrentProperties occurrentProperties, Optional> cloudEventTypeMapper) { + ObjectMapper om = objectMapper.orElseGet(ObjectMapper::new); + CloudEventTypeMapper cm = cloudEventTypeMapper.orElseGet(OccurrentMongoAutoConfiguration::newDefaultCloudEventTypeMapper); + return new JacksonCloudEventConverter.Builder(om, occurrentProperties.getCloudEventConverter().getCloudEventSource()) + .typeMapper(cm) .build(); } @Bean @ConditionalOnMissingBean(CloudEventTypeMapper.class) public CloudEventTypeMapper occurrentTypeMapper() { + return newDefaultCloudEventTypeMapper(); + } + + @NotNull + private static CloudEventTypeMapper newDefaultCloudEventTypeMapper() { return ReflectionCloudEventTypeMapper.qualified(); }