全局处理方法求案例?json转义问题,JAVA实体类number类型字段为null时,返回到json解析转为-1

Blade 未结 1 1457
冰心
冰心 2020-05-13 10:03
悬赏:5


这是单独手动加的方法,有办法全局加上吗?

https://sns.bladex.cn/q-100.html



image.png



参考Application加上
/**
* 解决Jackson导致Long型数据精度丢失问题
*
* @return
*/
@Bean("jackson2ObjectMapperBuilderCustomizer")
public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
  Jackson2ObjectMapperBuilderCustomizer customizer = new Jackson2ObjectMapperBuilderCustomizer() {
     @Override
     public void customize(Jackson2ObjectMapperBuilder jacksonObjectMapperBuilder) {
        jacksonObjectMapperBuilder.serializerByType(Long.class, ToStringSerializer.instance)
           .serializerByType(Long.TYPE, ToStringSerializer.instance);


     }
  };
  return customizer;
}





1条回答
  •  smallchill
    smallchill (楼主)
    2020-05-13 11:00

    帖子里已经把逻辑所在的类贴出来了,是这个:org.springblade.core.tool.jackson.BladeBeanSerializerModifier

    找到对应的序列化逻辑,改成你想要的就行

    0 讨论(0)
提交回复