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

cn.k7g.alloy.core.objectmapper.TimestampSerializer Maven / Gradle / Ivy

package cn.k7g.alloy.core.objectmapper;

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

import java.io.IOException;
import java.util.Optional;

public class TimestampSerializer extends JsonSerializer {
    @Override
    public void serialize(Timestamp timestamp, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        Long value = Optional.ofNullable(timestamp).map(v -> v.get()).orElse(null);
        if (value == null) {
            jsonGenerator.writeNull();
            return;
        }
        jsonGenerator.writeNumber(value);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy