package com.yuchen.saas.park.api.config;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;
import java.util.Optional;

public class LongToStringSerializer extends StdSerializer<Long> {
    protected LongToStringSerializer() {
        super(long.class);
    }

    @Override
    public void serialize(Long value, JsonGenerator gen, SerializerProvider provider) throws IOException {
        gen.writeString(Optional.ofNullable(value).map(String::valueOf).orElse(""));
    }
}
