package com.eco.common.mapper.core.handler;

import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.BeanSerializerModifier;

import java.util.List;

/**
 * @Description: FieldMapperBeanSerializerModifier
 * @Author: GaoKun Wang
 * @Date: 2024/7/1
 */
public class FieldMapperBeanSerializerModifier extends BeanSerializerModifier {

    @Override
    public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc,
                                                     List<BeanPropertyWriter> beanProperties) {
        for (BeanPropertyWriter writer : beanProperties) {
            // 如果序列化器为 FieldMapperHandler 的话 将 Null 值也交给他处理
            if (writer.getSerializer() instanceof FieldMapperHandler serializer) {
                writer.assignNullSerializer(serializer);
            }
        }
        return beanProperties;
    }
}
