Posts

Showing posts with the label Boot

[Quick Solution] Add Another Custom ObjectMapper Configuration in Spring Boot

[Issue]   I have a system that provides Rest APIs using Spring Boot, communicating smoothly with clients via JSON. Recently, I encountered a situation where I needed to communicate with a new server using slightly different JSON communication rules.   To accommodate this, I added a custom ObjectMapper Bean ("myObjectMapper") to my configuration.   However, after doing so, the previously functioning Rest APIs started to misbehave, giving the impression that the newly added myObjectMapper was being used even in the existing JSON communications. @Configuration public class MyConfiguration { @Bean ObjectMapper myObjectMapper () { ObjectMapper mapper1 = new ObjectMapper(); mapper1.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false ); // ... return mapper1; } } [Solution]   To address this issue, I added the following Primary Bean configuration for "jacksonObjectMapper" with the annotation @ConditionalOnMissingBean(name = "ja...