Skip to content

Commit 739c140

Browse files
author
Jevgeni Koltšin
committed
Gson string adapter (empty string to null)
1 parent bba8403 commit 739c140

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=1.1.1
1+
version=1.1.2

src/main/java/com/creatubbles/api/CreatubblesAPI.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import java.io.File;
44
import java.io.IOException;
5+
import java.lang.reflect.Type;
56
import java.nio.file.Files;
67

8+
import com.google.gson.*;
79
import org.glassfish.jersey.client.ClientProperties;
810
import org.glassfish.jersey.client.JerseyClient;
911
import org.glassfish.jersey.client.JerseyClientBuilder;
@@ -22,8 +24,6 @@
2224
import com.creatubbles.api.response.gallery.CreateUserGalleryResponse;
2325
import com.creatubbles.api.response.user.UserProfileResponse;
2426
import com.creatubbles.api.util.EndPoints;
25-
import com.google.gson.Gson;
26-
import com.google.gson.GsonBuilder;
2727

2828

2929
@SuppressWarnings("deprecation")
@@ -39,6 +39,7 @@ public class CreatubblesAPI {
3939
.registerTypeAdapter(GetCreationsResponse.class, new GetCreationsResponse())
4040
.registerTypeAdapter(CreateCreationResponse.class, new CreateCreationResponse())
4141
.registerTypeAdapter(CreationsUploadsResponse.class, new CreationsUploadsResponse())
42+
.registerTypeAdapter(String.class, new StringAdapter())
4243
.create();
4344

4445
public final static JerseyClient CLIENT = JerseyClientBuilder
@@ -83,4 +84,14 @@ public static void main(String[] args) throws IOException {
8384
System.out.println("-Finish-");
8485
}
8586

87+
static class StringAdapter implements JsonDeserializer<String> {
88+
89+
public String deserialize(JsonElement json, Type typeOfT,
90+
JsonDeserializationContext context)
91+
throws JsonParseException {
92+
String asString = json.getAsJsonPrimitive().getAsString();
93+
return asString != null && asString.isEmpty() ? null : asString;
94+
}
95+
}
96+
8697
}

0 commit comments

Comments
 (0)