DateFormatter dateFormatter = new DateFormatter(new Date());
JSONArray jsonActivities = new JSONArray();
for (ActivityDTO activity : activities.getPagedSet())
{
AvatarUrlGenerator actorUrlGen = new AvatarUrlGenerator(EntityType.PERSON);
JSONObject jsonActivity = new JSONObject();
jsonActivity.put("commentCount", activity.getCommentCount());
jsonActivity.put("likeCount", activity.getLikeCount());
jsonActivity.put("destinationDisplayName", activity.getDestinationStream().getDisplayName());
jsonActivity.put("destinationUniqueIdentifier", activity.getDestinationStream().getUniqueIdentifier());
jsonActivity.put("destinationType", activity.getDestinationStream().getType());
jsonActivity.put("actorAvatarPath", actorUrlGen.getSmallAvatarUrl(activity.getActor().getAvatarId()));
jsonActivity.put("actorDisplayName", activity.getActor().getDisplayName());
jsonActivity.put("actorUniqueIdentifier", activity.getActor().getUniqueIdentifier());
jsonActivity.put("actorType", activity.getActor().getType());
jsonActivity.put("verb", activity.getVerb());
jsonActivity.put("postedTimeAgo", dateFormatter.timeAgo(activity.getPostedTime()));
jsonActivity.put("baseObjectType", activity.getBaseObjectType().toString());
jsonActivity.put("activityId", activity.getId());
jsonActivity.put("originalActorAvatarPath",
actorUrlGen.getSmallAvatarUrl(activity.getOriginalActor().getAvatarId()));
jsonActivity.put("originalActorActivityId", activity.getOriginalActor().getAvatarId());
jsonActivity.put("originalActorDisplayName", activity.getOriginalActor().getDisplayName());
jsonActivity.put("originalActorUniqueIdentifier", activity.getOriginalActor().getUniqueIdentifier());
jsonActivity.put("originalActorType", activity.getOriginalActor().getType());