Commit 0df951079be8e3dcf1d7186f41a7a95a1c33ab4a

Authored by YunaiV
1 parent cdc4255d

fix:【框架】TimestampLocalDateTimeSerializer 的 fieldName 为空的情况,对应 https://github.com…

…/YunaiV/ruoyi-vue-pro/issues/1032
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<LocalDateTi
23 23  
24 24 @Override
25 25 public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
26   - String fieldName = gen.getOutputContext().getCurrentName();
27   - Class<?> clazz = gen.getOutputContext().getCurrentValue().getClass();
28   - Field field = ReflectUtil.getField(clazz, fieldName);
29 26 // 情况一:有 JsonFormat 自定义注解,则使用它。https://github.com/YunaiV/ruoyi-vue-pro/pull/1019
30   - JsonFormat[] jsonFormats = field.getAnnotationsByType(JsonFormat.class);
31   - if (jsonFormats.length > 0) {
32   - String pattern = jsonFormats[0].pattern();
33   - DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
34   - gen.writeString(formatter.format(value));
35   - return;
  27 + String fieldName = gen.getOutputContext().getCurrentName();
  28 + if (fieldName != null) {
  29 + Class<?> clazz = gen.getOutputContext().getCurrentValue().getClass();
  30 + Field field = ReflectUtil.getField(clazz, fieldName);
  31 + JsonFormat[] jsonFormats = field.getAnnotationsByType(JsonFormat.class);
  32 + if (jsonFormats.length > 0) {
  33 + String pattern = jsonFormats[0].pattern();
  34 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
  35 + gen.writeString(formatter.format(value));
  36 + return;
  37 + }
36 38 }
37 39  
38 40 // 情况二:默认将 LocalDateTime 对象,转换为 Long 时间戳
... ...