package it.integry.integrywmsnative.core.rest.serializer;

import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

import java.lang.reflect.Type;
import java.time.LocalDate;

import it.integry.integrywmsnative.core.utility.UtilityDate;

public class LocalDateSerializer implements JsonSerializer<LocalDate> {

    @Override
    public JsonElement serialize(LocalDate src, Type typeOfSrc, JsonSerializationContext context) {
        String dateString = UtilityDate.formatDate(src, UtilityDate.COMMONS_DATE_FORMATS.DMY_SLASH);

        return src == null ? null : new JsonPrimitive(dateString);
    }
}
