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

ph.com.nightowlstudios.entity.serializer.LocalDateTimeSerializer Maven / Gradle / Ivy

There is a newer version: 6.21.1
Show newest version
package ph.com.nightowlstudios.entity.serializer;

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

/**
 * @author Joseph Harvey Angeles - yev
 * @since 4/10/21
 **/
public class LocalDateTimeSerializer extends StdSerializer {

  protected LocalDateTimeSerializer() {
    this(LocalDateTime.class);
  }

  protected LocalDateTimeSerializer(Class t) {
    super(t);
  }

  @Override
  public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider provider) throws IOException {
    Long epoch = value.atZone(ZoneId.systemDefault()).toInstant().getEpochSecond();
    gen.writeString(epoch.toString());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy