package com.changhu.support.fastjson2.serializer;

import com.alibaba.fastjson2.JSONWriter;
import com.alibaba.fastjson2.writer.ObjectWriter;
import com.changhu.common.db.BaseEnum;

import java.lang.reflect.Type;

/**
 * @author 20252
 * @createTime 2024/8/28 下午4:19
 * @desc 数据库枚举到前端
 */
public class DbEnumSerializer implements ObjectWriter<BaseEnum<?>> {
    public static final DbEnumSerializer instance = new DbEnumSerializer();

    private DbEnumSerializer() {
    }

    @Override
    public void write(JSONWriter jsonWriter, Object object, Object fieldName, Type fieldType, long features) {
        if (object == null) {
            jsonWriter.writeNull();
            return;
        }
        jsonWriter.writeAny(((BaseEnum<?>) object).serializer());
    }
}
