diff --git a/build.gradle b/build.gradle index 6e3b3e15..4306a6c5 100644 --- a/build.gradle +++ b/build.gradle @@ -94,7 +94,8 @@ checkstyleMain.doLast { } dependencies { - compile 'com.google.code.gson:gson:2.7' + compile 'com.squareup.okio:okio:1.9.0' + compile 'com.squareup.moshi:moshi:1.2.0' compile 'com.annimon:stream:1.1.1' compile 'com.squareup.okhttp3:okhttp:3.4.0-RC1' compile 'com.google.protobuf:protobuf-java:3.0.0-beta-3' diff --git a/src/main/java/com/pokegoapi/auth/GoogleAuthJson.java b/src/main/java/com/pokegoapi/auth/GoogleAuthJson.java index 9d6427f7..be71193b 100644 --- a/src/main/java/com/pokegoapi/auth/GoogleAuthJson.java +++ b/src/main/java/com/pokegoapi/auth/GoogleAuthJson.java @@ -15,18 +15,18 @@ package com.pokegoapi.auth; -import com.google.gson.annotations.SerializedName; +import com.squareup.moshi.Json; public class GoogleAuthJson { - @SerializedName("device_code") + @Json(name = "device_code") String deviceCode; - @SerializedName("user_code") + @Json(name = "user_code") String userCode; - @SerializedName("verification_url") + @Json(name = "verification_url") String verificationUrl; - @SerializedName("expires_in") + @Json(name = "expires_in") int expiresIn; - @SerializedName("interval") + @Json(name = "interval") int interval; public String getDeviceCode() { diff --git a/src/main/java/com/pokegoapi/auth/GoogleAuthTokenJson.java b/src/main/java/com/pokegoapi/auth/GoogleAuthTokenJson.java index eba7fbea..4d0b58e7 100644 --- a/src/main/java/com/pokegoapi/auth/GoogleAuthTokenJson.java +++ b/src/main/java/com/pokegoapi/auth/GoogleAuthTokenJson.java @@ -15,19 +15,19 @@ package com.pokegoapi.auth; -import com.google.gson.annotations.SerializedName; +import com.squareup.moshi.Json; public class GoogleAuthTokenJson { private String error; - @SerializedName("access_token") + @Json(name = "access_token") private String accessToken; - @SerializedName("token_type") + @Json(name = "token_type") private String tokenType; - @SerializedName("expires_in") + @Json(name = "expires_in") private int expiresIn; - @SerializedName("refresh_token") + @Json(name = "refresh_token") private String refreshToken; - @SerializedName("id_token") + @Json(name = "id_token") private String idToken; public String getError() { diff --git a/src/main/java/com/pokegoapi/auth/GoogleLogin.java b/src/main/java/com/pokegoapi/auth/GoogleLogin.java index 9924bb3a..ad80f8c5 100644 --- a/src/main/java/com/pokegoapi/auth/GoogleLogin.java +++ b/src/main/java/com/pokegoapi/auth/GoogleLogin.java @@ -16,10 +16,9 @@ package com.pokegoapi.auth; import POGOProtos.Networking.Envelopes.RequestEnvelopeOuterClass.RequestEnvelope.AuthInfo; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import com.pokegoapi.exceptions.LoginFailedException; import com.pokegoapi.util.Log; +import com.squareup.moshi.Moshi; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -80,9 +79,9 @@ public AuthInfo login(String username, String password) throws LoginFailedExcept Response response = client.newCall(request).execute(); - Gson gson = new GsonBuilder().create(); + Moshi moshi = new Moshi.Builder().build(); - GoogleAuthJson googleAuth = gson.fromJson(response.body().string(), GoogleAuthJson.class); + GoogleAuthJson googleAuth = moshi.adapter(GoogleAuthJson.class).fromJson(response.body().string()); Log.d(TAG, "Get user to go to:" + googleAuth.getVerificationUrl() + " and enter code:" + googleAuth.getUserCode()); @@ -125,8 +124,8 @@ private GoogleAuthTokenJson poll(GoogleAuthJson json) throws URISyntaxException, Response response = client.newCall(request).execute(); - Gson gson = new GsonBuilder().create(); - GoogleAuthTokenJson token = gson.fromJson(response.body().string(), GoogleAuthTokenJson.class); + Moshi moshi = new Moshi.Builder().build(); + GoogleAuthTokenJson token = moshi.adapter(GoogleAuthTokenJson.class).fromJson(response.body().string()); if (token.getError() == null) { return token; diff --git a/src/main/java/com/pokegoapi/auth/PtcLogin.java b/src/main/java/com/pokegoapi/auth/PtcLogin.java index db5fbae9..fe124245 100644 --- a/src/main/java/com/pokegoapi/auth/PtcLogin.java +++ b/src/main/java/com/pokegoapi/auth/PtcLogin.java @@ -16,9 +16,8 @@ package com.pokegoapi.auth; import POGOProtos.Networking.Envelopes.RequestEnvelopeOuterClass.RequestEnvelope.AuthInfo; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import com.pokegoapi.exceptions.LoginFailedException; +import com.squareup.moshi.Moshi; import lombok.Getter; import okhttp3.Cookie; import okhttp3.CookieJar; @@ -122,9 +121,9 @@ public AuthInfo login(String username, String password) throws LoginFailedExcept Response getResponse = client.newCall(get).execute(); - Gson gson = new GsonBuilder().create(); + Moshi moshi = new Moshi.Builder().build(); - PtcAuthJson ptcAuth = gson.fromJson(getResponse.body().string(), PtcAuthJson.class); + PtcAuthJson ptcAuth = moshi.adapter(PtcAuthJson.class).fromJson(getResponse.body().string()); HttpUrl url = HttpUrl.parse(LOGIN_URL).newBuilder() .addQueryParameter("lt", ptcAuth.getLt()) @@ -152,7 +151,7 @@ public AuthInfo login(String username, String password) throws LoginFailedExcept String body = response.body().string(); if (body.length() > 0) { - PtcError ptcError = gson.fromJson(body, PtcError.class); + PtcError ptcError = moshi.adapter(PtcError.class).fromJson(body); if (ptcError.getError() != null && ptcError.getError().length() > 0) { throw new LoginFailedException(); }