time formatter such as '10:15' or '10:15:30'.

The ISO time formatter that formats or parses a time without an offset, such as '10:15' or '10:15:30'.
This commit is contained in:
Hacker 2021-08-27 03:51:28 +00:00 committed by Gitee
parent 2fcee0ff80
commit 689d7394e2
1 changed files with 8 additions and 13 deletions

View File

@ -45,30 +45,25 @@ public class PigJavaTimeModule extends SimpleModule {
public PigJavaTimeModule() { public PigJavaTimeModule() {
super(PackageVersion.VERSION); super(PackageVersion.VERSION);
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN);
// ======================= 时间序列化规则 =============================== // ======================= 时间序列化规则 ===============================
// yyyy-MM-dd HH:mm:ss // yyyy-MM-dd HH:mm:ss
this.addSerializer(LocalDateTime.class, this.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(dateTimeFormatter));
new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)));
// yyyy-MM-dd // yyyy-MM-dd
this.addSerializer(LocalDate.class, this.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ISO_LOCAL_DATE));
new LocalDateSerializer(DateTimeFormatter.ofPattern(DatePattern.NORM_DATE_PATTERN)));
// HH:mm:ss // HH:mm:ss
this.addSerializer(LocalTime.class, this.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ISO_LOCAL_TIME));
new LocalTimeSerializer(DateTimeFormatter.ofPattern(DatePattern.NORM_TIME_PATTERN)));
// Instant 类型序列化 // Instant 类型序列化
this.addSerializer(Instant.class, InstantSerializer.INSTANCE); this.addSerializer(Instant.class, InstantSerializer.INSTANCE);
// ======================= 时间反序列化规则 ============================== // ======================= 时间反序列化规则 ==============================
// yyyy-MM-dd HH:mm:ss // yyyy-MM-dd HH:mm:ss
this.addDeserializer(LocalDateTime.class, this.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(dateTimeFormatter));
new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)));
// yyyy-MM-dd // yyyy-MM-dd
this.addDeserializer(LocalDate.class, this.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ISO_LOCAL_DATE));
new LocalDateDeserializer(DateTimeFormatter.ofPattern(DatePattern.NORM_DATE_PATTERN)));
// HH:mm:ss // HH:mm:ss
this.addDeserializer(LocalTime.class, this.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ISO_LOCAL_TIME));
new LocalTimeDeserializer(DateTimeFormatter.ofPattern(DatePattern.NORM_TIME_PATTERN)));
// Instant 反序列化 // Instant 反序列化
this.addDeserializer(Instant.class, InstantDeserializer.INSTANT); this.addDeserializer(Instant.class, InstantDeserializer.INSTANT);
} }