org.kiwiproject.jackson.ser.InstantEpochTimeSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kiwi Show documentation
Show all versions of kiwi Show documentation
Kiwi is a utility library. We really like Google's Guava, and also use Apache Commons.
But if they don't have something we need, and we think it is useful, this is where we put it.
package org.kiwiproject.jackson.ser;
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.Instant;
/**
* Jackson serializer that converts an {@link Instant} into milliseconds since the epoch.
*/
public class InstantEpochTimeSerializer extends StdSerializer {
/**
* Create a new instance that serializes {@link Instant} to epoch millis.
*/
public InstantEpochTimeSerializer() {
super(Instant.class);
}
@Override
public void serialize(Instant value,
JsonGenerator jsonGenerator,
SerializerProvider provider) throws IOException {
jsonGenerator.writeNumber(value.toEpochMilli());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy