若依框架Long精度丢失问题
之前用若依框架,发现long类型的数据如果过长会精度丢失,试了很多方法,结果和定时任务的下次执行时间显示有8小时差,不多说,下面的方法可以解决这2个问题:@Configurationpublic class LongToStringJsonConfig {@Bean("jackson2ObjectMapperBuilderCustomizer")public Jackson2ObjectMappe
·
之前用若依框架,发现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;
}
}
更多推荐
已为社区贡献1条内容
所有评论(0)