Skip to content

Instantly share code, notes, and snippets.

@aaronmcadam
Created April 2, 2014 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aaronmcadam/9930654 to your computer and use it in GitHub Desktop.
Save aaronmcadam/9930654 to your computer and use it in GitHub Desktop.
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