Skip to content
This repository was archived by the owner on Jan 5, 2019. It is now read-only.

Commit 65a4955

Browse files
committed
Minor cleanup using convenience methods for json
1 parent a306ade commit 65a4955

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

src/main/java/com/scorpiac/javarant/Rant.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static Rant fromJson(JsonObject json) {
4848
json.get("num_downvotes").getAsInt(),
4949
json.get("text").getAsString(),
5050
getImage(json.get("attached_image")),
51-
Util.jsonToList(json.get("tags").getAsJsonArray(), JsonElement::getAsString).toArray(new String[0]),
51+
Util.jsonToList(json.getAsJsonArray("tags"), JsonElement::getAsString).toArray(new String[0]),
5252
json.get("num_comments").getAsInt()
5353
);
5454
}
@@ -92,7 +92,7 @@ public boolean fetchComments() {
9292
return false;
9393

9494
// Get the comments.
95-
commentsFromJson(json.get("comments").getAsJsonArray());
95+
commentsFromJson(json.getAsJsonArray("comments"));
9696

9797
return true;
9898
}

src/main/java/com/scorpiac/javarant/User.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ public boolean fetchData() {
108108
fetched = true;
109109

110110
// JSON objects.
111-
JsonObject profileJson = json.get("profile").getAsJsonObject();
112-
JsonObject contentJson = profileJson.get("content").getAsJsonObject();
113-
JsonObject subContentJson = contentJson.get("content").getAsJsonObject();
114-
JsonObject countsJson = contentJson.get("counts").getAsJsonObject();
115-
JsonObject avatarJson = profileJson.get("avatar").getAsJsonObject();
111+
JsonObject profileJson = json.getAsJsonObject("profile");
112+
JsonObject contentJson = profileJson.getAsJsonObject("content");
113+
JsonObject subContentJson = contentJson.getAsJsonObject("content");
114+
JsonObject countsJson = contentJson.getAsJsonObject("counts");
115+
JsonObject avatarJson = profileJson.getAsJsonObject("avatar");
116116

117117
// Set all the fields.
118118
username = profileJson.get("username").getAsString();

0 commit comments

Comments
 (0)