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

io.orangebeard.client.entity.DateSerializer Maven / Gradle / Ivy

There is a newer version: 3.0.1
Show newest version
package io.orangebeard.client.entity;

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.ZoneId;

class DateSerializer extends JsonSerializer {

    private final ZoneId zoneId;

    public DateSerializer() {
        this.zoneId = ZoneId.systemDefault();
    }

    public DateSerializer(ZoneId zoneId) {
        this.zoneId = zoneId;
    }

    @Override
    public void serialize(LocalDateTime value, JsonGenerator jgen, SerializerProvider serializers) throws IOException {
        jgen.writeRawValue(String.valueOf(value.atZone(zoneId).toInstant().toEpochMilli()));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy