In order to use the @ResponseBody
and @RequestBody
annotations in Spring MVC to translate HTTP messages to JSON objects and vice versa, I need to add the MappingJackson2HttpMessageConverter
to the list of HttpMessageConverters as such:
@Configuration
@EnableWebMvc
@ComponentScan("spring.mvc")
public class MyWebConfig implements WebMvcConfigurer {
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(new MappingJackson2HttpMessageConverter());
}
}
Additionally, I had to add the following dependency to my build.gradle
file:
implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.1'
my question is: why doesn’t the package in which the MappingJackson2HttpMessageConverter
class included (spring-web
) includes the jackson-databind:2.14.1
artifact as a dependency? Or at least – where is it documented that I need it in my classpath?