springboot如何防止Long类型精度丢失

配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@Configuration
public class WebMvcAutoConfiguration {

@Bean
@Primary
public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
final JavaTimeModule module = new JavaTimeModule();
// module.addSerializer(LocalDateTime.class, LocalDateTimeSerializer.INSTANCE);
// module.addDeserializer(LocalDateTime.class, LocalDateTimeDeserializer.INSTANCE);

module.addSerializer(Long.class, ToStringSerializer.instance);
module.addSerializer(Long.TYPE, ToStringSerializer.instance);

return builder.createXmlMapper(false).modulesToInstall(module).build();
}
}