jafea7-ctbrec-v5.3.0-based/src/main/java/ctbrec/io/InstantJsonAdapter.java

22 lines
593 B
Java

package ctbrec.io;
import java.io.IOException;
import java.time.Instant;
import com.squareup.moshi.JsonAdapter;
import com.squareup.moshi.JsonReader;
import com.squareup.moshi.JsonWriter;
public class InstantJsonAdapter extends JsonAdapter<Instant> {
@Override
public Instant fromJson(JsonReader reader) throws IOException {
long timeInEpochMillis = reader.nextLong();
return Instant.ofEpochMilli(timeInEpochMillis);
}
@Override
public void toJson(JsonWriter writer, Instant time) throws IOException {
writer.value(time.toEpochMilli());
}
}