All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.houkunlin.system.dict.starter.jackson.DictDefaultSerializerProviderImpl Maven / Gradle / Ivy

Go to download

系统数据字典自动翻译成字典文本。可集合系统数据库中存储的用户数据字典,也可使用枚举做系统数据字典,主要用在返回数据给前端时自动把字典值翻译成字典文本信息; The system data dictionary is automatically translated into dictionary text. The user data dictionary stored in the system database can be aggregated, and the enumeration can also be used as the system data dictionary. It is mainly used to automatically translate dictionary values into dictionary text information when returning data to the front end.

The newest version!
package com.houkunlin.system.dict.starter.jackson;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider;
import com.fasterxml.jackson.databind.ser.SerializerFactory;
import com.houkunlin.system.dict.starter.json.DictTextJsonSerializer;

/**
 * 自定义 SerializerProvider ,主要是为了处理数据字典的 null 值处理问题
 *
 * @author HouKunLin
 * @since 1.4.3
 */
public class DictDefaultSerializerProviderImpl extends DefaultSerializerProvider {
    public DictDefaultSerializerProviderImpl() {
    }

    public DictDefaultSerializerProviderImpl(final SerializerProvider src, final SerializationConfig config, final SerializerFactory f) {
        super(src, config, f);
    }

    public DictDefaultSerializerProviderImpl(final DefaultSerializerProvider src) {
        super(src);
    }

    @Override
    public DefaultSerializerProvider createInstance(final SerializationConfig config, final SerializerFactory jsf) {
        return new DictDefaultSerializerProviderImpl(this, config, jsf);
    }

    /**
     * 重写此方法,为了给使用了 {@link com.houkunlin.system.dict.starter.json.DictText} 注解的字段自定义的 null 值序列化器
     *
     * @param property BeanProperty
     * @return JsonSerializer
     * @throws JsonMappingException 异常
     */
    @Override
    public JsonSerializer findNullValueSerializer(final BeanProperty property) throws JsonMappingException {
        final JsonSerializer serializer = DictTextJsonSerializer.getJsonSerializer(property);
        if (serializer != null) {
            return serializer;
        }
        return super.findNullValueSerializer(property);
    }
}