package com.docus.server.common.serializer;

import com.docus.core.util.Convert;
import com.docus.infrastructure.web.json.JsonSerializerModule;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.time.ZoneId;
import java.util.Date;
import java.util.TimeZone;

public class DefJsonSerializerModule extends JsonSerializerModule {
    public DefJsonSerializerModule() {

        addSerializer(Date.class, new JsonSerializer<Date>() {
            @Override
            public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
                jsonGenerator.writeString(date == null ? null : Convert.toString(date, Convert.DATA_FORMAT_DATETIME_SLASH, TimeZone.getTimeZone(ZoneId.systemDefault())));
            }
        });
    }

}
