'SpringBoot: Enabling WRAP_ROOT_VALUE feature using custom Jackson2ObjectMapperBuilder shuts off Swagger3

I've read many articles/threads and what not about how to enable Jackson's WRAP_ROOT_VALUE feature in SpringBoot (v2.2.2RELEASE) and none of them really work, until I came across the following solution which does the trick!

@Configuration
public class JacksonConfig

  @Bean
  @Primary
  public Jackson2ObjectMapperBuilder jacksonBuilder() {
    Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder() //
        .featuresToEnable(SerializationFeature.WRAP_ROOT_VALUE); // enables wrapping 
    return builder;
  }

This works since it replaces SpringBoot/Swagger's serialization definitions with this custom one.

The problem: Swagger3 stop working! I access swagger using this link: http://localhost:8080/swagger-ui/index.html and it stopped working! If I remove the JacksonConfig then everything is back to normal.

My assumption is that Swagger initializes Jackson in some way that ruins my custom one.

Any idea?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source