使用 FastJsonHttpMessageConverter 进行返回值序列化时Long类型字段返回字符串;
期望返回数字类型,添加如下处理
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
/**
* Long.class to String
*. to Number
* @param converters
*/
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
for (HttpMessageConverter httpMessageConverter:converters){
if (httpMessageConverter instanceof FastJsonHttpMessageConverter){
FastJsonConfig fastJsonConfig = ((FastJsonHttpMessageConverter) httpMessageConverter).getFastJsonConfig();
SerializeConfig serializeConfig = fastJsonConfig.getSerializeConfig();
serializeConfig.put(Long.class,ToStringSerializer.instance);
fastJsonConfig.setSerializeConfig(serializeConfig);
}
}
}
}
自定义
ToStringSeriali