Created
March 27, 2018 14:22
-
-
Save mengjiann/cce8fee0bb5b443e8875853fc7e8ae08 to your computer and use it in GitHub Desktop.
spring-boot-cloud-feign-config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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