@Configuration标签:return,builder,配置,private,Localdatetime,DATE,全局,FORMATTER,class From: https://www.cnblogs.com/zhuoneng/p/17749915.html
public class LocalDateTimeSerializerConfig {
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm:ss");
private LocalDateTimeSerializer localDateTimeSerializer() {
return new LocalDateTimeSerializer(DATE_TIME_FORMATTER);
}
private LocalDateTimeDeserializer localDateTimeDeserializer() {
return new LocalDateTimeDeserializer(DATE_TIME_FORMATTER);
}
private LocalDateSerializer localDateSerializer() {
return new LocalDateSerializer(DATE_FORMATTER);
}
private LocalDateDeserializer localDateDeserializer() {
return new LocalDateDeserializer(DATE_FORMATTER);
}
private LocalTimeSerializer localTimeSerializer() {
return new LocalTimeSerializer(TIME_FORMATTER);
}
private LocalTimeDeserializer localTimeDeserializer() {
return new LocalTimeDeserializer(TIME_FORMATTER);
}
@Bean
public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
return builder -> {
builder.serializerByType(LocalDateTime.class, localDateTimeSerializer());
builder.deserializerByType(LocalDateTime.class, localDateTimeDeserializer());
builder.serializerByType(LocalDate.class, localDateSerializer());
builder.deserializerByType(LocalDate.class, localDateDeserializer());
builder.serializerByType(LocalTime.class, localTimeSerializer());
builder.deserializerByType(LocalTime.class, localTimeDeserializer());
};
}
}