最近发现项目服务间,通过openfeign调用API时,为null的Boolean类型,接收端反系列化后变为false了,经查发现是通用组件中做了处理,特记录下。
主要是设置了这个
SerializerFeature.WriteNullBooleanAsFalse
@Bean
@ConditionalOnProperty(prefix = "upex.web.support.fastjson.message-converter", name = "enabled", havingValue = "true", matchIfMissing = true)
public XssFastJsonHttpMessageConverter messageConverter() {String instanceName = ParamApolloUtils.getInstanceNameByParam(SpringContextUtil.getLowerApplicationName());FastJsonConfig fastJsonConfig = new FastJsonConfig();fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteNullBooleanAsFalse, SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteBigDecimalAsPlain);//对外输出转换为字符串if (webSupportConfig.isUseLongWriteString()) {SerializeConfig serializeConfig = fastJsonConfig.getSerializeConfig();serializeConfig.put(BigInteger.class, ToStringSerializer.instance);serializeConfig.put(Long.class, ToStringSerializer.instance);serializeConfig.put(Long.TYPE, ToStringSerializer.instance);}if (webSupportConfig.isUseBigDecimalWriteString()) {fastJsonConfig.setSerializeFilters(BigDecimalValueFilter.instance);}XssFastJsonHttpMessageConverter converter = new XssFastJsonHttpMessageConverter(instanceName);converter.setFastJsonConfig(fastJsonConfig);converter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON, MediaType.valueOf("feign/json")));return converter;
}