Skip to content

Commit bffcbb9

Browse files
committed
[1.2.1-SNAPSHOT]
BasicProvider Gson registration for LocalDate and LocalDateTime types added
1 parent 22c9679 commit bffcbb9

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Library supports all available EtherScan *API* calls for all available *Ethereum
1515
**Gradle**
1616
```groovy
1717
dependencies {
18-
compile "com.github.goodforgod:java-etherscan-api:1.2.0"
18+
compile "com.github.goodforgod:java-etherscan-api:1.2.1"
1919
}
2020
```
2121

@@ -24,7 +24,7 @@ dependencies {
2424
<dependency>
2525
<groupId>com.github.goodforgod</groupId>
2626
<artifactId>java-etherscan-api</artifactId>
27-
<version>1.2.0</version>
27+
<version>1.2.1</version>
2828
</dependency>
2929
```
3030

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ dependencies {
3838
implementation "org.jetbrains:annotations:22.0.0"
3939
implementation "com.google.code.gson:gson:2.8.9"
4040

41-
testImplementation "junit:junit:4.13.1"
41+
testImplementation "junit:junit:4.13.2"
4242
}
4343

4444
test {

gradle.properties

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
groupId=com.github.goodforgod
22
artifactId=java-etherscan-api
3-
artifactVersion=1.2.0
4-
buildNumber=1
3+
artifactVersion=1.2.1-SNAPSHOT
54

65

76
##### GRADLE #####
87
org.gradle.daemon=true
98
org.gradle.parallel=true
109
org.gradle.configureondemand=true
1110
org.gradle.caching=true
12-
org.gradle.jvmargs=-Dfile.encoding=UTF-8
11+
org.gradle.jvmargs=-Dfile.encoding=UTF-8

src/main/java/io/api/etherscan/core/impl/BasicProvider.java

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.api.etherscan.core.impl;
22

3-
import com.google.gson.Gson;
3+
import com.google.gson.*;
44
import io.api.etherscan.error.ApiException;
55
import io.api.etherscan.error.EtherScanException;
66
import io.api.etherscan.error.ParseException;
@@ -10,6 +10,9 @@
1010
import io.api.etherscan.model.utility.StringResponseTO;
1111
import io.api.etherscan.util.BasicUtils;
1212

13+
import java.time.LocalDate;
14+
import java.time.LocalDateTime;
15+
import java.time.format.DateTimeFormatter;
1316
import java.util.Map;
1417

1518
/**
@@ -40,7 +43,22 @@ abstract class BasicProvider {
4043
this.module = "&module=" + module;
4144
this.baseUrl = baseUrl;
4245
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+
4462
}
4563

4664
<T> T convert(final String json, final Class<T> tClass) {

0 commit comments

Comments
 (0)