Not clear how to inject custom ObjectMapper for @SpringBootTest(SomeController.class)

26 Views Asked by At

Affects: \3.1.5

I am using custom configuration for an ObjectMapper like that:

@Autowired
private ObjectMapper objectMapper;

@Override
public void extendMessageConverters (List<HttpMessageConverter<?>> converters) {
    converters.stream()
            .filter(x -> x instanceof MappingJackson2HttpMessageConverter)
            .forEach(x -> ((MappingJackson2HttpMessageConverter) x).setObjectMapper(objectMapper));
}

It is working OK in app, but I can't inject the same configuration to my JUnits. Is @SpringBootTest(Controller.class) possible to inject custom ObjectMapper or extendMessageConverter?

I tried injecting the previous JsonConfiguration and doing the following, but it did not work:

mockMvc = MockMvcBuilders.standaloneSetup(controller).setControllerAdvice(jsonConfiguration).build();

Please provide more details or workaround. Thanks!

0

There are 0 best solutions below