yml
spring:
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
serialization:
#格式化输出
indent_output: true
#忽略无法转换的对象
fail_on_empty_beans: false
properties
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
spring.jackson.serialization.indent_output=true
spring.jackson.serialization.fail_on_empty_beans=false
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
public Date addtime;
@Configuration public class JacksonConfig { /** * jackson将数值转为字符串的转换器:解决精度 丢失 * @return */ /* @Bean public ObjectMapper objectMapper(){ ObjectMapper objectMapper = new ObjectMapper(); SimpleModule simpleModule = new SimpleModule(); simpleModule.addSerializer(BigInteger.class, ToStringSerializer.instance); simpleModule.addSerializer(BigDecimal.class, ToStringSerializer.instance); simpleModule.addSerializer(Long.class, ToStringSerializer.instance); simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); objectMapper.registerModule(simpleModule); objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); objectMapper.setTimeZone(TimeZone.getTimeZone("GMT+8")); return objectMapper; }*/ @Bean public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() { Jackson2ObjectMapperBuilderCustomizer customizer = new Jackson2ObjectMapperBuilderCustomizer() { @Override public void customize(Jackson2ObjectMapperBuilder jacksonObjectMapperBuilder) { jacksonObjectMapperBuilder // 以后后端响应的Integer类型的值 前端无需转换 .serializerByType(Long.class, ToStringSerializer.instance) .serializerByType(BigDecimal.class,ToStringSerializer.instance) .serializerByType(Long.TYPE, ToStringSerializer.instance); } }; return customizer; } }