package com.cpop.core.strategy.json;

import com.cpop.common.utils.StringUtils;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import lombok.NoArgsConstructor;

import java.io.IOException;
import java.util.ArrayList;

/**
 * 序列化时 逗号拼接转数组  "0","1","2" -> ["0","1","2"]
 *
 * @author Lynn
 * @date 2022/11/8 14:45
 */
@NoArgsConstructor
public class StringToArraySerializer extends JsonSerializer<String> {

    @Override
    public void serialize(String str, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        if (null != str) {
            String[] split = str.split(",");
            jsonGenerator.writeArray(split, 0, split.length);
        }
    }
}

