浏览代码

update 字典数据json序列化工具加一个 bean的非空判断

itino 2 年之前
父节点
当前提交
e41a58b10d
共有 1 个文件被更改,包括 5 次插入3 次删除
  1. 5 3
      ruoyi-common/src/main/java/com/ruoyi/common/jackson/DictDataJsonSerializer.java

+ 5 - 3
ruoyi-common/src/main/java/com/ruoyi/common/jackson/DictDataJsonSerializer.java

@@ -1,5 +1,6 @@
 package com.ruoyi.common.jackson;
 
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.fasterxml.jackson.core.JsonGenerator;
 import com.fasterxml.jackson.databind.BeanProperty;
@@ -29,9 +30,10 @@ public class DictDataJsonSerializer extends JsonSerializer<String> implements Co
     @Override
     public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
         try {
-            String label = SpringUtils.getBean(DictService.class).getDictLabel(dictType, value);
-            if (StrUtil.isNotBlank(label)) {
-                gen.writeString(label);
+            DictService dictService = SpringUtils.getBean(DictService.class);
+            if (ObjectUtil.isNotNull(dictService)) {
+                String label = dictService.getDictLabel(dictType, value);
+                gen.writeString(StrUtil.isNotBlank(label) ? label : value);
             } else {
                 gen.writeString(value);
             }