package org.jeecg.modules.stm.common.json;

import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;


/**
 * @Author: yzh
 * @Date 2023/7/27 20:11
 * @Description:
 */
public class String2ArrayDeserialize extends JsonDeserializer<List<Serializable>> {
    @Override
    public List<Serializable> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {
        String values = jsonParser.getValueAsString();
        if(StringUtils.isEmpty(values)){
            return null;
        }
        return Arrays.asList(StringUtils.split(values,","));
    }
}
