package com.xunmei.common.core.json;


import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

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

/**
 * 图片前缀
 */
public class ImageListSerializer extends JsonSerializer<List<String>> {

    @Override
    public void serialize(final List<String> value, final JsonGenerator gen, final SerializerProvider serializers) throws IOException {
        gen.writeStartArray();
        for (final String s : Optional.ofNullable(value)
                .orElse(Collections.emptyList())) {
            gen.writeString(s);
        }
        gen.writeEndArray();
    }
}
