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

0 comments on commit c874e6a

Please sign in to comment.