cloud.eppo.ufc.dto.adapters.DateSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk-common-jvm Show documentation
Show all versions of sdk-common-jvm Show documentation
Eppo SDK for JVM shared library
package cloud.eppo.ufc.dto.adapters;
import static cloud.eppo.Utils.getISODate;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import java.io.IOException;
import java.util.Date;
/**
* This adapter for Date allows gson to serialize to UTC ISO 8601 (vs. its default of local
* timezone)
*/
public class DateSerializer extends StdSerializer {
protected DateSerializer(Class t) {
super(t);
}
public DateSerializer() {
this(null);
}
@Override
public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider)
throws IOException {
jgen.writeString(getISODate(value));
}
}