Skip to content

Commit

Permalink
refactor: Refactor how the kayenta object mapper is being configured …
Browse files Browse the repository at this point in the history
…to allow overriding from kayenta plugins

- ObjectMapperSubtypeConfigurer objectMapperSubtypeConfigurer is defined as a bean
- there's no need to autowire the mapper to configure but instead configure it when creating the kayentaObjectMapper bean
  • Loading branch information
ovidiupopa07 committed Dec 7, 2023
1 parent 9c9ae50 commit 49991e0
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,25 @@ public ObjectMapperSubtypeConfigurer.ClassSubtypeLocator assetSpecSubTypeLocator
ImmutableList.of("com.netflix.kayenta.canary.providers.metrics"));
}

@Primary
@Bean
ObjectMapper kayentaObjectMapper(ObjectMapper mapper) {
return mapper;
@ConditionalOnMissingBean
public ObjectMapperSubtypeConfigurer objectMapperSubtypeConfigurer() {
return new ObjectMapperSubtypeConfigurer(true);
}

@Autowired
public void objectMapper(
@Primary
@Bean
ObjectMapper kayentaObjectMapper(
ObjectMapper mapper,
ObjectMapperSubtypeConfigurer objectMapperSubtypeConfigurer,
List<ObjectMapperSubtypeConfigurer.SubtypeLocator> subtypeLocators,
KayentaSerializationConfigurationProperties kayentaSerializationConfigurationProperties) {
configureObjectMapper(mapper, subtypeLocators, kayentaSerializationConfigurationProperties);
configureObjectMapper(
mapper,
objectMapperSubtypeConfigurer,
subtypeLocators,
kayentaSerializationConfigurationProperties);
return mapper;
}

public static void configureObjectMapperFeatures(
Expand All @@ -141,9 +148,10 @@ public static void configureObjectMapperFeatures(

private void configureObjectMapper(
ObjectMapper objectMapper,
ObjectMapperSubtypeConfigurer objectMapperSubtypeConfigurer,
List<ObjectMapperSubtypeConfigurer.SubtypeLocator> subtypeLocators,
KayentaSerializationConfigurationProperties kayentaSerializationConfigurationProperties) {
new ObjectMapperSubtypeConfigurer(true).registerSubtypes(objectMapper, subtypeLocators);
objectMapperSubtypeConfigurer.registerSubtypes(objectMapper, subtypeLocators);
configureObjectMapperFeatures(objectMapper, kayentaSerializationConfigurationProperties);
}

Expand Down

0 comments on commit 49991e0

Please sign in to comment.