Jackson 反序列化BigDecimal精度丢失问题

ObjectMapper默认Number转换为Double

解决方式: 设置ObjectMapper的默认转换方式

ObjectMapper mapper = new ObjectMapper()
mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);

所有配置代码:

@CompileStatic
@TypeChecked
@Configuration
class RestTemplateConfig {

    @LoadBalanced
    @Bean
    RestTemplateExt restTemplate() {
        return newRestTemplate()
    }

    private RestTemplateExt newRestTemplate() {
        RestTemplateExt restTemplate = new RestTemplateExt()
        List> converterList = restTemplate.getMessageConverters()
        for (HttpMessageConverter item : converterList) {
            if (item.getClass() == StringHttpMessageConverter.class) {
                item = new StringHttpMessageConverter(StandardCharsets.UTF_8)
            }
            if (item.getClass() == 

你可能感兴趣的:(java,测试,json)