Skip to content

Commit

Permalink
Fixed problem with spring-boot autoconfiguration in which it previous…
Browse files Browse the repository at this point in the history
…ly failed to create a default cloud event converter if no type mapper was specified explicitly
  • Loading branch information
johanhaleby committed Nov 21, 2023
1 parent 9a2a26b commit e5f0aa3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -117,16 +118,22 @@ public SubscriptionModel occurrentCompetingDurableSubscriptionModel(MongoTemplat

@Bean
@ConditionalOnMissingBean(CloudEventConverter.class)
public <T> CloudEventConverter<?> occurrentCloudEventConverter(Optional<ObjectMapper> objectMapper, OccurrentProperties occurrentProperties, CloudEventTypeMapper<T> cloudEventTypeMapper) {
ObjectMapper mapper = objectMapper.orElseGet(ObjectMapper::new);
return new JacksonCloudEventConverter.Builder<T>(mapper, occurrentProperties.getCloudEventConverter().getCloudEventSource())
.typeMapper(cloudEventTypeMapper)
public <T> CloudEventConverter<?> occurrentCloudEventConverter(Optional<ObjectMapper> objectMapper, OccurrentProperties occurrentProperties, Optional<CloudEventTypeMapper<T>> cloudEventTypeMapper) {
ObjectMapper om = objectMapper.orElseGet(ObjectMapper::new);
CloudEventTypeMapper<T> cm = cloudEventTypeMapper.orElseGet(OccurrentMongoAutoConfiguration::newDefaultCloudEventTypeMapper);
return new JacksonCloudEventConverter.Builder<T>(om, occurrentProperties.getCloudEventConverter().getCloudEventSource())
.typeMapper(cm)
.build();
}

@Bean
@ConditionalOnMissingBean(CloudEventTypeMapper.class)
public CloudEventTypeMapper<?> occurrentTypeMapper() {
return newDefaultCloudEventTypeMapper();
}

@NotNull
private static <T> CloudEventTypeMapper<T> newDefaultCloudEventTypeMapper() {
return ReflectionCloudEventTypeMapper.qualified();
}

Expand Down

0 comments on commit e5f0aa3

Please sign in to comment.