From 49991e0346b53444e0cb081a5198c05b017968f8 Mon Sep 17 00:00:00 2001 From: Ovidiu Popa Date: Thu, 7 Dec 2023 14:24:22 +0200 Subject: [PATCH] refactor: Refactor how the kayenta object mapper is being configured 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 --- .../kayenta/config/KayentaConfiguration.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/kayenta-core/src/main/java/com/netflix/kayenta/config/KayentaConfiguration.java b/kayenta-core/src/main/java/com/netflix/kayenta/config/KayentaConfiguration.java index 18b6f6033..2fb97f411 100644 --- a/kayenta-core/src/main/java/com/netflix/kayenta/config/KayentaConfiguration.java +++ b/kayenta-core/src/main/java/com/netflix/kayenta/config/KayentaConfiguration.java @@ -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 subtypeLocators, KayentaSerializationConfigurationProperties kayentaSerializationConfigurationProperties) { - configureObjectMapper(mapper, subtypeLocators, kayentaSerializationConfigurationProperties); + configureObjectMapper( + mapper, + objectMapperSubtypeConfigurer, + subtypeLocators, + kayentaSerializationConfigurationProperties); + return mapper; } public static void configureObjectMapperFeatures( @@ -141,9 +148,10 @@ public static void configureObjectMapperFeatures( private void configureObjectMapper( ObjectMapper objectMapper, + ObjectMapperSubtypeConfigurer objectMapperSubtypeConfigurer, List subtypeLocators, KayentaSerializationConfigurationProperties kayentaSerializationConfigurationProperties) { - new ObjectMapperSubtypeConfigurer(true).registerSubtypes(objectMapper, subtypeLocators); + objectMapperSubtypeConfigurer.registerSubtypes(objectMapper, subtypeLocators); configureObjectMapperFeatures(objectMapper, kayentaSerializationConfigurationProperties); }