uk.gov.service.payments.commons.api.json.ApiResponseDateTimeSerializer Maven / Gradle / Ivy
package uk.gov.service.payments.commons.api.json;
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.time.ZonedDateTime;
import static uk.gov.service.payments.commons.model.ApiResponseDateTimeFormatter.ISO_INSTANT_MILLISECOND_PRECISION;
public class ApiResponseDateTimeSerializer extends StdSerializer {
public ApiResponseDateTimeSerializer() {
this(null);
}
private ApiResponseDateTimeSerializer(Class t) {
super(t);
}
@Override
public void serialize(ZonedDateTime value, JsonGenerator gen, SerializerProvider sp) throws IOException {
gen.writeString(ISO_INSTANT_MILLISECOND_PRECISION.format(value));
}
}