package com.changhu.support.fastjson2.deserialze;

import com.alibaba.fastjson2.JSONReader;
import com.alibaba.fastjson2.reader.ObjectReader;
import com.changhu.common.db.BaseEnum;

import java.lang.reflect.Type;

/**
 * @author 20252
 * @createTime 2024/8/28 下午4:39
 * @desc DbEnumDeserializer...
 */
public class DbEnumDeserializer implements ObjectReader<BaseEnum<Object>> {

    public static final DbEnumDeserializer instance = new DbEnumDeserializer();

    private DbEnumDeserializer() {
    }

    @SuppressWarnings("unchecked")
    @Override
    public BaseEnum<Object> readObject(JSONReader jsonReader, Type fieldType, Object fieldName, long features) {
        Object value = jsonReader.readAny();
        if (value == null) {
            return null;
        }
        return BaseEnum.valueOf((Class<BaseEnum<Object>>) fieldType, value);
    }
}
