-
-
Save carolineartz/7f6ab2496376ef5874c83e84b1359afc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.crowdlab.deserializers; | |
import com.google.gson.JsonElement; | |
import com.google.gson.JsonObject; | |
public class DeserializerHelper { | |
private JsonObject mJsonObject; | |
public DeserializerHelper(JsonObject obj) { | |
mJsonObject = obj; | |
} | |
private JsonElement getElement(String key) { | |
if (mJsonObject == null) { return null; } | |
JsonElement element = mJsonObject.get(key); | |
if (!element.isJsonNull()) { | |
return element; | |
} | |
} | |
public Long deserializeLong(String key) { | |
Long value = -1L; | |
JsonElement obj = getElement(key); | |
if (obj != null) { | |
value = obj.getAsLong(); | |
} | |
return value; | |
} | |
public String deserializeString(String key) { | |
String value = new String(); | |
JsonElement obj = getElement(key); | |
if (obj != null) { | |
value = obj.getAsString(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment