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

org.rdlinux.luava.json.jackson.serializer.LocalDateTimeSerializer Maven / Gradle / Ivy

The newest version!
package org.rdlinux.luava.json.jackson.serializer;

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.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class LocalDateTimeSerializer extends JsonSerializer {
    public static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
    //public static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    private static final LocalDateTimeSerializer instance = new LocalDateTimeSerializer();

    private LocalDateTimeSerializer() {
    }

    public static LocalDateTimeSerializer getInstance() {
        return instance;
    }

    @Override
    public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        String format = dateTimeFormatter.format(value);
        gen.writeString(format);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy