Permalink
Browse files

Improve getting value from JSON

null-safe
json.getString -> z_F4JInternalParseUtil#getRawString
json.getLong -> z_F4JInternalParseUtil#getLong
  • Loading branch information...
roundrop committed Mar 13, 2013
1 parent 648f117 commit c874e6a115a6086bb11b0e020da6d767225f5377
@@ -18,9 +18,10 @@
import facebook4j.Cover; import facebook4j.Cover;
import facebook4j.FacebookException; import facebook4j.FacebookException;
import facebook4j.internal.org.json.JSONException;
import facebook4j.internal.org.json.JSONObject; import facebook4j.internal.org.json.JSONObject;
import static facebook4j.internal.util.z_F4JInternalParseUtil.*;
/** /**
* @author Ryuji Yamashita - roundrop at gmail.com * @author Ryuji Yamashita - roundrop at gmail.com
*/ */
@@ -32,13 +33,9 @@
private final long offsetY; private final long offsetY;
/*package*/CoverJSONImpl(JSONObject json) throws FacebookException { /*package*/CoverJSONImpl(JSONObject json) throws FacebookException {
try { id = getRawString("id", json);
id = json.getString("id"); source = getRawString("source", json);
source = json.getString("source"); offsetY = getLong("offset_y", json);
offsetY = json.getLong("offset_y");
} catch (JSONException jsone) {
throw new FacebookException(jsone);
}
} }
public String getId() { public String getId() {
@@ -25,6 +25,8 @@
import facebook4j.internal.org.json.JSONException; import facebook4j.internal.org.json.JSONException;
import facebook4j.internal.org.json.JSONObject; import facebook4j.internal.org.json.JSONObject;
import static facebook4j.internal.util.z_F4JInternalParseUtil.*;
/** /**
* @author Ryuji Yamashita - roundrop at gmail.com * @author Ryuji Yamashita - roundrop at gmail.com
*/ */
@@ -51,13 +53,9 @@
} }
private void init(JSONObject json) throws FacebookException { private void init(JSONObject json) throws FacebookException {
try { id = getRawString("id", json);
id = json.getString("id"); name = getRawString("name", json);
name = json.getString("name"); relationship = getRawString("relationship", json);
relationship = json.getString("relationship");
} catch (JSONException jsone) {
throw new FacebookException(jsone.getMessage(), jsone);
}
} }
public String getId() { public String getId() {
@@ -25,6 +25,8 @@
import facebook4j.internal.org.json.JSONException; import facebook4j.internal.org.json.JSONException;
import facebook4j.internal.org.json.JSONObject; import facebook4j.internal.org.json.JSONObject;
import static facebook4j.internal.util.z_F4JInternalParseUtil.*;
/** /**
* @author Ryuji Yamashita - roundrop at gmail.com * @author Ryuji Yamashita - roundrop at gmail.com
*/ */
@@ -49,12 +51,8 @@
} }
private void init(JSONObject json) throws FacebookException { private void init(JSONObject json) throws FacebookException {
try { id = getRawString("id", json);
id = json.getString("id"); name = getRawString("name", json);
name = json.getString("name");
} catch (JSONException jsone) {
throw new FacebookException(jsone);
}
} }
public String getId() { public String getId() {
@@ -20,9 +20,10 @@
import facebook4j.IdName; import facebook4j.IdName;
import facebook4j.conf.Configuration; import facebook4j.conf.Configuration;
import facebook4j.internal.http.HttpResponse; import facebook4j.internal.http.HttpResponse;
import facebook4j.internal.org.json.JSONException;
import facebook4j.internal.org.json.JSONObject; import facebook4j.internal.org.json.JSONObject;
import static facebook4j.internal.util.z_F4JInternalParseUtil.*;
/** /**
* @author Ryuji Yamashita - roundrop at gmail.com * @author Ryuji Yamashita - roundrop at gmail.com
*/ */
@@ -48,12 +49,8 @@
} }
private void init(JSONObject json) throws FacebookException { private void init(JSONObject json) throws FacebookException {
try { id = getRawString("id", json);
id = json.getString("id"); name = getRawString("name", json);
name = json.getString("name");
} catch (JSONException jsone) {
throw new FacebookException(jsone);
}
} }
public String getId() { public String getId() {
@@ -433,12 +433,8 @@ public String toString() {
private final String link; private final String link;
/*package*/ActionJSONImpl(JSONObject json) throws FacebookException { /*package*/ActionJSONImpl(JSONObject json) throws FacebookException {
try { name = getRawString("name", json);
name = json.getString("name"); link = getRawString("link", json);
link = json.getString("link");
} catch (JSONException jsone) {
throw new FacebookException(jsone);
}
} }
public String getName() { public String getName() {
@@ -437,7 +437,7 @@ public String toString() {
JSONObject yearJSON = json.getJSONObject("year"); JSONObject yearJSON = json.getJSONObject("year");
year = new IdNameEntityJSONImpl(yearJSON); year = new IdNameEntityJSONImpl(yearJSON);
} }
type = json.getString("type"); type = getRawString("type", json);
if (!json.isNull("school")) { if (!json.isNull("school")) {
JSONObject schoolJSON = json.getJSONObject("school"); JSONObject schoolJSON = json.getJSONObject("school");
school = new IdNameEntityJSONImpl(schoolJSON); school = new IdNameEntityJSONImpl(schoolJSON);
@@ -588,7 +588,7 @@ public String toString() {
with.add(new IdNameEntityJSONImpl(withJSONArray.getJSONObject(i))); with.add(new IdNameEntityJSONImpl(withJSONArray.getJSONObject(i)));
} }
} }
description = json.getString("description"); description = getRawString("description", json);
} catch (JSONException jsone) { } catch (JSONException jsone) {
throw new FacebookException(jsone.getMessage() + ":" + json.toString(), jsone); throw new FacebookException(jsone.getMessage() + ":" + json.toString(), jsone);
} }
@@ -656,12 +656,8 @@ private UserJSONImpl getOuterType() {
private final long size; private final long size;
VideoUploadLimitsJSONImpl(JSONObject json) throws FacebookException { VideoUploadLimitsJSONImpl(JSONObject json) throws FacebookException {
try { length = getLong("length", json);
length = json.getLong("length"); size = getLong("size", json);
size = json.getLong("size");
} catch (JSONException jsone) {
throw new FacebookException(jsone);
}
} }
public long getLength() { public long getLength() {
@@ -728,12 +724,8 @@ public String toString() {
JSONObject positionJSONObject = json.getJSONObject("position"); JSONObject positionJSONObject = json.getJSONObject("position");
position = new IdNameEntityJSONImpl(positionJSONObject); position = new IdNameEntityJSONImpl(positionJSONObject);
} }
if (!json.isNull("start_date")) { startDate = getRawString("start_date", json);
startDate = json.getString("start_date"); endDate = getRawString("end_date", json);
}
if (!json.isNull("end_date")) {
endDate = json.getString("end_date");
}
} catch (JSONException jsone) { } catch (JSONException jsone) {
throw new FacebookException(jsone); throw new FacebookException(jsone);
} }

0 comments on commit c874e6a

Please sign in to comment.