diff --git a/src/org/thoughtcrime/redphone/signaling/RedPhoneAccountManager.java b/src/org/thoughtcrime/redphone/signaling/RedPhoneAccountManager.java index 121f1232e9..f835d0acf2 100644 --- a/src/org/thoughtcrime/redphone/signaling/RedPhoneAccountManager.java +++ b/src/org/thoughtcrime/redphone/signaling/RedPhoneAccountManager.java @@ -1,7 +1,5 @@ package org.thoughtcrime.redphone.signaling; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import com.squareup.okhttp.MediaType; import com.squareup.okhttp.OkHttpClient; import com.squareup.okhttp.Request; @@ -9,6 +7,7 @@ import com.squareup.okhttp.RequestBody; import com.squareup.okhttp.Response; import org.thoughtcrime.securesms.util.Base64; +import org.thoughtcrime.securesms.util.JsonUtils; import org.whispersystems.libaxolotl.util.guava.Optional; import org.whispersystems.textsecure.api.push.TrustStore; @@ -52,7 +51,7 @@ public class RedPhoneAccountManager { builder.header("Authorization", "Basic " + Base64.encodeBytes((login + ":" + password).getBytes())); if (gcmId.isPresent()) { - String body = new ObjectMapper().writeValueAsString(new RedPhoneGcmId(gcmId.get())); + String body = JsonUtils.toJson(new RedPhoneGcmId(gcmId.get())); builder.put(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), body)); } else { builder.delete(); @@ -70,7 +69,7 @@ public class RedPhoneAccountManager { } public void createAccount(String verificationToken, RedPhoneAccountAttributes attributes) throws IOException { - String body = new ObjectMapper().writeValueAsString(attributes); + String body = JsonUtils.toJson(attributes); Request request = new Request.Builder() .url(baseUrl + "/api/v1/accounts/token/" + verificationToken) diff --git a/src/org/thoughtcrime/redphone/signaling/SignalingSocket.java b/src/org/thoughtcrime/redphone/signaling/SignalingSocket.java index 8879f5dcdf..d3b954da75 100644 --- a/src/org/thoughtcrime/redphone/signaling/SignalingSocket.java +++ b/src/org/thoughtcrime/redphone/signaling/SignalingSocket.java @@ -30,6 +30,7 @@ import org.thoughtcrime.redphone.signaling.signals.RingingSignal; import org.thoughtcrime.redphone.signaling.signals.ServerSignal; import org.thoughtcrime.redphone.signaling.signals.Signal; import org.thoughtcrime.redphone.util.LineReader; +import org.thoughtcrime.securesms.util.JsonUtils; import org.whispersystems.textsecure.api.push.TrustStore; import java.io.IOException; @@ -182,7 +183,7 @@ public class SignalingSocket { case 404: throw new NoSuchUserException("No such redphone user."); case 402: throw new ServerMessageException(new String(response.getBody())); case 401: throw new LoginFailedException("Initiate threw 401"); - case 200: return new ObjectMapper().readValue(response.getBody(), SessionDescriptor.class); + case 200: return JsonUtils.fromJson(response.getBody(), SessionDescriptor.class); default: throw new SignalingException("Unknown response: " + response.getStatusCode()); } } catch (IOException e) { diff --git a/src/org/thoughtcrime/securesms/util/JsonUtils.java b/src/org/thoughtcrime/securesms/util/JsonUtils.java index 92862d647b..284d0a9e1b 100644 --- a/src/org/thoughtcrime/securesms/util/JsonUtils.java +++ b/src/org/thoughtcrime/securesms/util/JsonUtils.java @@ -15,6 +15,10 @@ public class JsonUtils { objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); } + public static T fromJson(byte[] serialized, Class clazz) throws IOException { + return fromJson(new String(serialized), clazz); + } + public static T fromJson(String serialized, Class clazz) throws IOException { return objectMapper.readValue(serialized, clazz); }