I have the following situation where i have multiple MappingJackson2HttpMessageConverter both of them using a shared ObjectMapper that has a single mixin added on it.
@Bean
public ObjectMapper objectMapper(){
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.addMixin(Item.class, ItemMixin.class);
return objectMapper;
}
@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter(){
MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter(objectMapper());
return mappingJackson2HttpMessageConverter;
}
The application is SpringBoot(i know that springboot does its own default instantiation of message converters) but the problem is that when i call an endpoint that has a list of items returned i get a 500 because the line:
objectMapper.addMixin(Item.class, ItemMixin.class);
somehow breaks and i don't understand why.
@GetMappring(.....)
public List<Item> getItems(){
return Arrays.asList(new Item(1), new Item(2));
}
I know that by default spring boot controller returns a string json if nothing is specified.The code is simplified for better readability.