I want to obtain the ObjectMapper
(or mappers) that Spring 5 creates, configures and uses to serialize and deserialize data exchanges on my Rest resources (i.e. to call readerForUpdating() on it or to provide further configuration such as adding mixins).
I've tried the solutions proposed in this question but none worked: I'm not using Spring Boot and neither of ObjectMapper
or MappingJackson2HttpMessageConverter
can be @Autowired
.
In particular, I've tried reconfiguring the ObjectMapper from the MappingJackson2HttpMessageConverter:
@EnableWebMvc
@Configuration
@EnableSwagger2
@ComponentScan(basePackages=...)
public class WebappConfig implements WebMvcConfigurer {
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
// ...
for(HttpMessageConverter<?> c : converters) {
if(c instanceof MappingJackson2HttpMessageConverter) {
ObjectMapper o = ((MappingJackson2HttpMessageConverter) c).getObjectMapper();
//o.configure(SerializationFeature.INDENT_OUTPUT, true);
o.addMixIn(WorkStamp.class, WorkStampApi.class);
}
}
//...
}
}
But that's not working either, as that mixin removes a field from the serialized object but the produced JSON still has that field.