Skip to content

Instantly share code, notes, and snippets.

@mengjiann
Created March 27, 2018 14:22
Show Gist options
  • Save mengjiann/cce8fee0bb5b443e8875853fc7e8ae08 to your computer and use it in GitHub Desktop.
Save mengjiann/cce8fee0bb5b443e8875853fc7e8ae08 to your computer and use it in GitHub Desktop.
spring-boot-cloud-feign-config
@Configuration
public class FeignClientConfig {
@Bean
Logger.Level feignLoggerLevel() {
return Logger.Level.FULL;
}
@Bean
public RequestInterceptor requestInterceptor(){
return new FeignRequestInterceptor();
}
@Bean
public Decoder feignDecoder() {
HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter(customObjectMapper());
ObjectFactory<HttpMessageConverters> objectFactory = () -> new HttpMessageConverters(jacksonConverter);
return new ResponseEntityDecoder(new SpringDecoder(objectFactory));
}
@Bean
public Encoder feignEncoder() {
HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter(customObjectMapper());
ObjectFactory<HttpMessageConverters> objectFactory = () -> new HttpMessageConverters(jacksonConverter);
return new SpringEncoder(objectFactory);
}
public ObjectMapper customObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
//Customize as much as you want
objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
return objectMapper;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment