|
1 | 1 | package io.api.etherscan.core.impl;
|
2 | 2 |
|
3 |
| -import com.google.gson.Gson; |
| 3 | +import com.google.gson.*; |
4 | 4 | import io.api.etherscan.error.ApiException;
|
5 | 5 | import io.api.etherscan.error.EtherScanException;
|
6 | 6 | import io.api.etherscan.error.ParseException;
|
|
10 | 10 | import io.api.etherscan.model.utility.StringResponseTO;
|
11 | 11 | import io.api.etherscan.util.BasicUtils;
|
12 | 12 |
|
| 13 | +import java.time.LocalDate; |
| 14 | +import java.time.LocalDateTime; |
| 15 | +import java.time.format.DateTimeFormatter; |
13 | 16 | import java.util.Map;
|
14 | 17 |
|
15 | 18 | /**
|
@@ -40,7 +43,22 @@ abstract class BasicProvider {
|
40 | 43 | this.module = "&module=" + module;
|
41 | 44 | this.baseUrl = baseUrl;
|
42 | 45 | this.executor = executor;
|
43 |
| - this.gson = new Gson(); |
| 46 | + this.gson = new GsonBuilder() |
| 47 | + .registerTypeAdapter(LocalDateTime.class, |
| 48 | + (JsonSerializer<LocalDateTime>) (src, typeOfSrc, context) -> new JsonPrimitive( |
| 49 | + src.format(DateTimeFormatter.ISO_DATE_TIME))) |
| 50 | + .registerTypeAdapter(LocalDate.class, |
| 51 | + (JsonSerializer<LocalDate>) (src, typeOfSrc, |
| 52 | + context) -> new JsonPrimitive(src.format(DateTimeFormatter.ISO_DATE))) |
| 53 | + .registerTypeAdapter(LocalDateTime.class, (JsonDeserializer<LocalDateTime>) (json, type, context) -> { |
| 54 | + String datetime = json.getAsJsonPrimitive().getAsString(); |
| 55 | + return LocalDateTime.parse(datetime, DateTimeFormatter.ISO_DATE_TIME); |
| 56 | + }) |
| 57 | + .registerTypeAdapter(LocalDate.class, (JsonDeserializer<LocalDate>) (json, type, context) -> { |
| 58 | + String datetime = json.getAsJsonPrimitive().getAsString(); |
| 59 | + return LocalDate.parse(datetime, DateTimeFormatter.ISO_DATE); |
| 60 | + }).create(); |
| 61 | + |
44 | 62 | }
|
45 | 63 |
|
46 | 64 | <T> T convert(final String json, final Class<T> tClass) {
|
|
0 commit comments