if (!json.isNull("from")) {
JSONObject fromJSONObject = json.getJSONObject("from");
from = new CategoryJSONImpl(fromJSONObject);
}
if (!json.isNull("to")) {
JSONArray toJSONArray = json.getJSONObject("to").getJSONArray("data");
to = new ArrayList<IdNameEntity>();
for (int i = 0; i < toJSONArray.length(); i++) {
JSONObject toJSONObject = toJSONArray.getJSONObject(i);
to.add(new IdNameEntityJSONImpl(toJSONObject));
}
} else {
to = Collections.emptyList();
}
message = getRawString("message", json);
if (!json.isNull("message_tags")) {
String raw = json.get("message_tags").toString();
if (raw.startsWith("[")) {
JSONArray tagsJSONArray = json.getJSONArray("message_tags");
messageTags = new ArrayList<Tag>();
for (int i = 0; i < tagsJSONArray.length(); i++) {
JSONObject tagJSONObject = tagsJSONArray.getJSONObject(i);
messageTags.add(new TagJSONImpl(tagJSONObject));
}
} else {
JSONObject tagsJSONObject = json.getJSONObject("message_tags");
Iterator ids = tagsJSONObject.keys();
while (ids.hasNext()) {
String id = (String) ids.next();
JSONArray tagsJSONArray = tagsJSONObject.getJSONArray(id);
messageTags = new ArrayList<Tag>();
for (int i = 0; i < tagsJSONArray.length(); i++) {
JSONObject tagJSONObject = tagsJSONArray.getJSONObject(i);
messageTags.add(new TagJSONImpl(tagJSONObject));
}
}
}
} else {
messageTags = Collections.emptyList();
}
picture = getURL("picture", json);
fullPicture = getURL("full_picture", json);
link = getURL("link", json);
name = getRawString("name", json);
caption = getRawString("caption", json);
description = getRawString("description", json);
source = getURL("source", json);
if (!json.isNull("properties")) {
JSONArray propertyJSONArray = json.getJSONArray("properties");
properties = new ArrayList<Post.Property>();
for (int i = 0; i < propertyJSONArray.length(); i++) {
JSONObject propertyJSONObject = propertyJSONArray.getJSONObject(i);
properties.add(new PropertyJSONImpl(propertyJSONObject));
}
} else {
properties = Collections.emptyList();
}
icon = getURL("icon", json);
if (!json.isNull("actions")) {
JSONArray actionJSONArray = json.getJSONArray("actions");
actions = new ArrayList<Post.Action>();
for (int i = 0; i < actionJSONArray.length(); i++) {
JSONObject actionJSONObject = actionJSONArray.getJSONObject(i);
actions.add(new ActionJSONImpl(actionJSONObject));
}
} else {
actions = Collections.emptyList();
}
if (!json.isNull("privacy")) {
JSONObject privacyJSONObject = json.getJSONObject("privacy");
privacy = new PrivacyJSONImpl(privacyJSONObject);
}
type = getRawString("type", json);
if (!json.isNull("shares")){
JSONObject sharesJSONObject = json.getJSONObject("shares");
if (!sharesJSONObject.isNull("count")){
sharesCount = getInt("count", sharesJSONObject);
}
}
if (!json.isNull("likes")) {
JSONObject likesJSONObject = json.getJSONObject("likes");
if (!likesJSONObject.isNull("data")) {
JSONArray list = likesJSONObject.getJSONArray("data");
final int size = list.length();
likes = new PagableListImpl<Like>(size, likesJSONObject);
for (int i = 0; i < size; i++) {
LikeJSONImpl like = new LikeJSONImpl(list.getJSONObject(i));
likes.add(like);
}
} else {
likes = new PagableListImpl<Like>(1, likesJSONObject);
}
} else {
likes = new PagableListImpl<Like>(0);
}
if (!json.isNull("place")) {
JSONObject placeJSONObject = json.getJSONObject("place");
place = new PlaceJSONImpl(placeJSONObject);
}
statusType = getRawString("status_type", json);
story = getRawString("story", json);
if (!json.isNull("story_tags")) {
JSONObject storyTagsJSONObject = json.getJSONObject("story_tags");
storyTags = new HashMap<String, Tag[]>();
@SuppressWarnings("unchecked")
Iterator<String> keys = storyTagsJSONObject.keys();
while (keys.hasNext()) {
String key = (String) keys.next();
JSONArray storyTagsJSONArray = storyTagsJSONObject.getJSONArray(key);
Tag[] tags = new Tag[storyTagsJSONArray.length()];
for (int i = 0; i < storyTagsJSONArray.length(); i++) {
JSONObject tag = storyTagsJSONArray.getJSONObject(i);
tags[i] = new TagJSONImpl(tag);
}
storyTags.put(key, tags);
}
} else {
storyTags = Collections.emptyMap();
}
if (!json.isNull("with_tags")) {
JSONArray withTagsJSONArray = json.getJSONObject("with_tags").getJSONArray("data");
withTags = new ArrayList<IdNameEntity>();
for (int i = 0; i < withTagsJSONArray.length(); i++) {
JSONObject withTagJSONObject = withTagsJSONArray.getJSONObject(i);
withTags.add(new IdNameEntityJSONImpl(withTagJSONObject));
}
} else {
withTags = Collections.emptyList();
}
if (!json.isNull("comments")) {
JSONObject commentsJSONObject = json.getJSONObject("comments");
if (!commentsJSONObject.isNull("data")) {
JSONArray list = commentsJSONObject.getJSONArray("data");
final int size = list.length();
comments = new PagableListImpl<Comment>(size, commentsJSONObject);
for (int i = 0; i < size; i++) {
CommentJSONImpl comment = new CommentJSONImpl(list.getJSONObject(i));
comments.add(comment);
}
} else {
comments = new PagableListImpl<Comment>(1, commentsJSONObject);
}