From 0df951079be8e3dcf1d7186f41a7a95a1c33ab4a Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 6 Dec 2025 09:28:00 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E3=80=90=E6=A1=86=E6=9E=B6?= =?UTF-8?q?=E3=80=91TimestampLocalDateTimeSerializer=20=E7=9A=84=20fieldNa?= =?UTF-8?q?me=20=E4=B8=BA=E7=A9=BA=E7=9A=84=E6=83=85=E5=86=B5=EF=BC=8C?= =?UTF-8?q?=E5=AF=B9=E5=BA=94=20https://github.com/YunaiV/ruoyi-vue-pro/is?= =?UTF-8?q?sues/1032?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TimestampLocalDateTimeSerializer.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/json/databind/TimestampLocalDateTimeSerializer.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/json/databind/TimestampLocalDateTimeSerializer.java index bed47e93bb..baefa50015 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/json/databind/TimestampLocalDateTimeSerializer.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/json/databind/TimestampLocalDateTimeSerializer.java @@ -23,16 +23,18 @@ public class TimestampLocalDateTimeSerializer extends JsonSerializer clazz = gen.getOutputContext().getCurrentValue().getClass(); - Field field = ReflectUtil.getField(clazz, fieldName); // 情况一:有 JsonFormat 自定义注解,则使用它。https://github.com/YunaiV/ruoyi-vue-pro/pull/1019 - JsonFormat[] jsonFormats = field.getAnnotationsByType(JsonFormat.class); - if (jsonFormats.length > 0) { - String pattern = jsonFormats[0].pattern(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern); - gen.writeString(formatter.format(value)); - return; + String fieldName = gen.getOutputContext().getCurrentName(); + if (fieldName != null) { + Class clazz = gen.getOutputContext().getCurrentValue().getClass(); + Field field = ReflectUtil.getField(clazz, fieldName); + JsonFormat[] jsonFormats = field.getAnnotationsByType(JsonFormat.class); + if (jsonFormats.length > 0) { + String pattern = jsonFormats[0].pattern(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern); + gen.writeString(formatter.format(value)); + return; + } } // 情况二:默认将 LocalDateTime 对象,转换为 Long 时间戳