All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.dft.amazon.common.DateSerializer Maven / Gradle / Ivy

There is a newer version: 2.1.9
Show newest version
package io.github.dft.amazon.common;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import lombok.SneakyThrows;

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

public class DateSerializer extends JsonSerializer {

    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss[.XXX]");

    @Override
    @SneakyThrows
    public void serialize(LocalDateTime localDateTime, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) {
        String formattedDateTime = localDateTime.format(formatter);
        jsonGenerator.writeString(formattedDateTime);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy