package com.ruoyi.common.config.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.ruoyi.common.utils.StringUtils;

import java.io.IOException;

public class SnowflakeToStringSerializer extends StdSerializer<Object> {

    public final static SnowflakeToStringSerializer instance = new SnowflakeToStringSerializer(Object.class);

    public SnowflakeToStringSerializer(Class<?> handledType) {
        super(handledType, false);
    }

    @Override
    public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException {
        gen.writeObject(snowflakeToString(value));
    }

    @Override
    public boolean isEmpty(SerializerProvider prov, Object value) {
        return StringUtils.isBlank(value.toString());
    }


    public final Object snowflakeToString(Object value) {
        return value.toString();
    }
}
