Add Jackson Instant serializers

This commit is contained in:
Colin McDonald 2016-06-17 01:11:28 -04:00
parent adf8d49334
commit 15a8ba70db
2 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,18 @@
package net.frozenorb.apiv3.serialization.jackson;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import java.io.IOException;
import java.time.Instant;
public final class InstantJsonDeserializer extends JsonDeserializer<Instant> {
@Override
public Instant deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
return Instant.ofEpochMilli(jsonParser.getValueAsLong());
}
}

View File

@ -0,0 +1,18 @@
package net.frozenorb.apiv3.serialization.jackson;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.time.Instant;
public final class InstantJsonSerializer extends JsonSerializer<Instant> {
@Override
public void serialize(Instant instant, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
jsonGenerator.writeNumber(instant.toEpochMilli());
}
}