FeignClient远程调用过滤为null的属性,不传null值只传有参数据
1.继承FeignClientsConfiguration
@Slf4j
@Configuration
public class RemoteFeignApiConfig extends FeignClientsConfiguration {
}
2.配置ObjectMapper的Bean,自定义Jackson库序列化JSON过滤null
@Bean
public ObjectMapper jacksonObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
return objectMapper;
}
3.完整代码
@Slf4j
@Configuration
public class RemoteFeignApiConfig extends FeignClientsConfiguration {
@Bean
public ObjectMapper jacksonObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
return objectMapper;
}
}