package fastweb.util;

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

import java.io.IOException;

/**
 * @author hengrui.liu   info
 * @date 21:11 25 12 2020
 * @Description
 * @Modified
 */
public class Date2LongSerializer extends JsonSerializer<String> {
    @Override
    public void serialize(String date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {//把Date转成Long
        int num = date.indexOf("T");
        if(num == -1){
            jsonGenerator.writeString(date);
        }else {
            jsonGenerator.writeString(date.substring(0, num));
        }
    }
}