【问题】Long转json精度丢失的问题

 

【问题】Long转json精度丢失的问题

 

解决方案

    
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

   /**
    * Long转json精度丢失的配置
    * @Return: void
    */
    @Override
    public void configureMessageConverters(List> converters) {
        MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new     
        MappingJackson2HttpMessageConverter();
        ObjectMapper objectMapper = new ObjectMapper();
        SimpleModule simpleModule = new SimpleModule();
        simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
        simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
        objectMapper.registerModule(simpleModule);
        jackson2HttpMessageConverter.setObjectMapper(objectMapper);
        converters.add(jackson2HttpMessageConverter);
    }

}

 

 

 

 

你可能感兴趣的:(问题异常,java,json,数据结构,gson)