package com.isxcode.oxygen.flysql.common;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * LocalDate Serializer
 *
 * @author ispong
 * @since 0.0.1
 */
public class LocalDateSerializer extends JsonSerializer<LocalDate> {

	@Override
	public void serialize(LocalDate value, JsonGenerator gen, SerializerProvider serializers)
			throws IOException {

		DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
		new ObjectMapper().writeValue(gen, dtf.format(value));
		//        gen.writeNumber(value.toInstant(ZoneOffset.ofHours(8)).toEpochMilli());
	}
}
