之前用若依框架,发现long类型的数据如果过长会精度丢失,试了很多方法,结果和定时任务的下次执行时间显示有8小时差,不多说,

下面的方法可以解决这2个问题:

 

@Configuration
public class LongToStringJsonConfig {
    @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)
                        .serializerByType(BigInteger.class, ToStringSerializer.instance);
            }
        };
        return customizer;
    }
}

 

Logo

快速构建 Web 应用程序

更多推荐