Well, WebMvcConfigurerAdapter
is deprecated. As of Spring 5.0 do this:
@SpringBootApplication(exclude = {JacksonAutoConfiguration.class}) public class Spring01Application { public static void main(String[] args) { SpringApplication.run(Spring01Application.class, args); } }
@Configuration public class WebConfig implements WebMvcConfigurer { @Bean public Gson gson() { GsonBuilder b = new GsonBuilder(); b.registerTypeAdapterFactory(HibernateProxyTypeAdapter.FACTORY); b.registerTypeAdapterFactory(DateTypeAdapter.FACTORY); b.registerTypeAdapterFactory(TimestampTypeAdapter.FACTORY); b.registerTypeAdapterFactory(LocalDateTypeAdapter.FACTORY); b.registerTypeAdapterFactory(LocalDateTimeTypeAdapter.FACTORY); return b.create(); } @Override public void configureMessageConverters( List<HttpMessageConverter<?>> converters) { StringHttpMessageConverter stringConverter = new StringHttpMessageConverter(); stringConverter.setWriteAcceptCharset(false); stringConverter.setSupportedMediaTypes(Collections .singletonList(MediaType.TEXT_PLAIN)); converters.add(stringConverter); converters.add(new ByteArrayHttpMessageConverter()); converters.add(new SourceHttpMessageConverter<>()); GsonHttpMessageConverter gsonHttpMessageConverter = new GsonHttpMessageConverter(); gsonHttpMessageConverter.setGson(gson()); gsonHttpMessageConverter.setSupportedMediaTypes(Arrays .asList(MediaType.APPLICATION_JSON)); converters.add(gsonHttpMessageConverter); } }
References
https://stackoverflow.com/questions/40786366/force-spring-boot-to-use-gson-instead-of-jackson