my goal is to configure the objectMapper
in the way that it only serialises element which are annotated with @JsonProperty
.
In order to do
To configure a message converter in plain spring-web, in this case to enable the Java 8 JSR-310 JavaTimeModule, you first need to implement WebMvcConfigurer
in your @Configuration
class and then override the configureMessageConverters
method:
@Override
public void configureMessageConverters(List> converters) {
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().modules(new JavaTimeModule(), new Jdk8Module()).build()
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
converters.add(new MappingJackson2HttpMessageConverter(objectMapper));
}
Like this you can register any custom defined ObjectMapper
in a Java-based Spring configuration.