package com.utopiaindustries.qualitychecker.utils.jackson;


import android.os.Build;

import androidx.annotation.RequiresApi;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.utopiaindustries.qualitychecker.utils.DateTimeUtils;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@RequiresApi(api = Build.VERSION_CODES.O)
public class LocalDateTimeSerializer extends JsonSerializer<LocalDateTime> {
	private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern( DateTimeUtils.HTML5_DATETIME_INPUT_FORMAT_WITH_SECONDS );

	@Override
	public void serialize( LocalDateTime value, JsonGenerator gen, SerializerProvider serializers ) throws IOException {
		gen.writeString( value.format( FORMATTER ) );
	}
}
