package fastweb.util;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.joda.time.DateTime;
import org.joda.time.LocalDateTime;

import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;

/**
 * @author: hengrui.liu
 * @createTime 2023年 03月20日 11:34
 **/

public class TimeStamp2StringSeriallizer extends JsonSerializer<Timestamp> {
    @Override
    public void serialize(Timestamp timestamp, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {//把Date转成Lon

        Date date =  new Date(timestamp.getTime());
        LocalDateTime dateTime = new LocalDateTime(date);
        jsonGenerator.writeString(dateTime.toString("yyyy-MM-dd hh:mm:ss"));
    }
}