dependency

pom.xml

<dependency>
  <groupId>com.fasterxml.jackson.datatype</groupId>
  <artifactId>jackson-datatype-hibernate4</artifactId>
  <version>2.8.4</version>
</dependency>

configure Jackson

Add or update your MVC configuration so as to register the Hibernate Module to the existing MappingJackson2HttpMessageConverter

@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport{

	@Override
    protected void extendMessageConverters( List<HttpMessageConverter<?>> converters ) {
        for ( HttpMessageConverter<?> converter : converters ) {
            if ( converter instanceof MappingJackson2HttpMessageConverter ) {
                MappingJackson2HttpMessageConverter jacksonConverter = (MappingJackson2HttpMessageConverter) converter;                
                ObjectMapper objectMapper = jacksonConverter.getObjectMapper();
                
        		//--- register hibernateModule in MappingJackson2HttpMessageConverter.objectMapper
                objectMapper.registerModule(new Hibernate4Module());

                //--- other configurations
                jacksonConverter.setPrettyPrint( true );
                objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);                
                objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
            }
        }
        
        super.configureMessageConverters(converters);
	}

}
Advertisements