com.notronix.etsy.impl.common.json.InstantAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of JEtsy Show documentation
Show all versions of JEtsy Show documentation
A Java implementation of a Java version of the Etsy API
package com.notronix.etsy.impl.common.json;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.time.Instant;
public class InstantAdapter extends TypeAdapter
{
@Override
public void write(JsonWriter out, Instant value) throws IOException {
out.value(Math.floor((double) value.toEpochMilli() / 1000d));
}
@Override
public Instant read(JsonReader in) throws IOException {
JsonToken token = in.peek();
if (token == JsonToken.NUMBER) {
return Instant.ofEpochMilli(in.nextLong() * 1000);
}
throw new IOException();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy