number类型js精度丢失,后端把long类型的字段转成字符串
仅
@JsonSerialize(using = ToStringSerializer.class)
无法解决所有问题
需要
PlanckConfiguration { () Jackson2ObjectMapperBuilderCustomizer () { Jackson2ObjectMapperBuilderCustomizer customizer = Jackson2ObjectMapperBuilderCustomizer() { (Jackson2ObjectMapperBuilder jacksonObjectMapperBuilder) { jacksonObjectMapperBuilder.serializerByType(Long.ToStringSerializer.) .serializerByType(Long.ToStringSerializer.)} }customizer} }
支持对所有含Long型数据进行全局过滤, 包括HashMap<xx, Long>, LinkedList<Long> ...
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
// 自定义大数字序列化
builder.serializerByType(Long.TYPE, ToStringSerializer.instance);
builder.serializerByType(Long.class, ToStringSerializer.instance);
builder.serializerByType(BigInteger.class, ToStringSerializer.instance);
builder.serializerByType(BigDecimal.class, ToStringSerializer.instance);
扫一扫访问 Blade技术社区 移动端