update 字典数据json序列化工具加一个 bean的非空判断
This commit is contained in:
parent
da94e89825
commit
e41a58b10d
@ -1,5 +1,6 @@
|
|||||||
package com.ruoyi.common.jackson;
|
package com.ruoyi.common.jackson;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
import com.fasterxml.jackson.databind.BeanProperty;
|
import com.fasterxml.jackson.databind.BeanProperty;
|
||||||
@ -29,9 +30,10 @@ public class DictDataJsonSerializer extends JsonSerializer<String> implements Co
|
|||||||
@Override
|
@Override
|
||||||
public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||||
try {
|
try {
|
||||||
String label = SpringUtils.getBean(DictService.class).getDictLabel(dictType, value);
|
DictService dictService = SpringUtils.getBean(DictService.class);
|
||||||
if (StrUtil.isNotBlank(label)) {
|
if (ObjectUtil.isNotNull(dictService)) {
|
||||||
gen.writeString(label);
|
String label = dictService.getDictLabel(dictType, value);
|
||||||
|
gen.writeString(StrUtil.isNotBlank(label) ? label : value);
|
||||||
} else {
|
} else {
|
||||||
gen.writeString(value);
|
gen.writeString(value);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user