com.base4j.mvc.conf.JsonConfig Maven / Gradle / Ivy
package com.base4j.mvc.conf;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import java.util.Arrays;
import java.util.List;
@Configuration
public class JsonConfig extends WebMvcConfigurerAdapter {
@Override
public void configureMessageConverters(List> converters) {
converters.add(mappingJackson2HttpMessageConverter());
}
@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
MappingJackson2HttpMessageConverter ret = new MappingJackson2HttpMessageConverter();
ret.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON, MediaType.TEXT_HTML));
ret.setObjectMapper(new JacksonCustomObjectMapper());
return ret;
}
}