Example usage for com.google.gson JsonSerializationContext serialize

List of usage examples for com.google.gson JsonSerializationContext serialize

Introduction

In this page you can find the example usage for com.google.gson JsonSerializationContext serialize.

Prototype

public JsonElement serialize(Object src);

Source Link

Document

Invokes default serialization on the specified object.

Usage

From source file:org.ambraproject.rhino.view.article.ArticleRevisionView.java

License:Open Source License

private JsonObject serializeIngestion(JsonSerializationContext context, ArticleIngestion ingestion) {
    JsonObject serialized = new JsonObject();
    JournalOutputView journalOutputView = JournalOutputView.getView(ingestion.getJournal());
    serialized.add("journal", context.serialize(journalOutputView));
    serialized.addProperty("ingestionNumber", ingestion.getIngestionNumber());
    serialized.addProperty("title", ingestion.getTitle());
    serialized.addProperty("publicationDate", ingestion.getPublicationDate().toLocalDate().toString());
    if (ingestion.getRevisionDate() != null) {
        serialized.addProperty("revisionDate", ingestion.getRevisionDate().toLocalDate().toString());
    }/*from  w w w . j a  v a2  s. c  o  m*/
    serialized.addProperty("publicationStage", ingestion.getPublicationStage());
    serialized.addProperty("articleType", ingestion.getArticleType());
    return serialized;
}

From source file:org.ambraproject.rhino.view.article.SyndicationOutputView.java

License:Open Source License

static JsonObject serializeBase(JsonSerializationContext context, Syndication syndication) {
    return context.serialize(syndication).getAsJsonObject();
}

From source file:org.ambraproject.rhino.view.article.SyndicationView.java

License:Open Source License

@Override
public JsonElement serialize(JsonSerializationContext context) {
    JsonObject serialized = new JsonObject();
    serialized.add("revision",
            context.serialize(ArticleRevisionView.getView(syndication.getArticleRevision())));
    serialized.addProperty("target", syndication.getTarget());
    serialized.addProperty("status", syndication.getStatus());
    serialized.addProperty("submissionCount", syndication.getSubmissionCount());
    serialized.add("lastSubmitTimestamp", context.serialize(syndication.getLastSubmitTimestamp()));
    return serialized;
}

From source file:org.ambraproject.rhino.view.comment.CommentFlagOutputView.java

License:Open Source License

@Override
public JsonElement serialize(JsonSerializationContext context) {
    JsonObject serialized = context.serialize(flag).getAsJsonObject();

    // Alias "comment" (the flag field containing the comment that the user submitted) to avoid ambiguity.
    // Should match the field name used for org.ambraproject.rhino.view.comment.CommentFlagInputView.body.
    serialized.add("body", serialized.remove("comment"));

    serialized.remove("userProfileID");
    if (flag.getUserProfileId() != null) {
        serialized.add("creator", context.serialize(new UserIdView(flag.getUserProfileId())));
    }/*from   w ww .j  a  v a2 s.c o  m*/

    serialized.add("flaggedComment", context.serialize(flaggedComment));

    return serialized;
}

From source file:org.ambraproject.rhino.view.comment.CommentNodeView.java

License:Open Source License

@Override
public JsonElement serialize(JsonSerializationContext context) {
    JsonObject serialized = CommentOutputView.serializeBase(context, comment, competingInterestStatement);
    serialized.add("parentArticle", context.serialize(parentArticle));
    return serialized;
}

From source file:org.ambraproject.rhino.view.comment.CommentOutputView.java

License:Open Source License

static JsonObject serializeBase(JsonSerializationContext context, Comment comment,
        CompetingInterestStatement competingInterestStatement) {
    JsonObject serialized = context.serialize(comment).getAsJsonObject();
    serialized.remove("userProfileID");

    final UserIdView userIdView;
    if (comment.getUserProfileID() != null) {
        userIdView = new UserIdView(comment.getUserProfileID());
        serialized.add("creator", context.serialize(userIdView));
    }//  w  w  w. j av  a  2 s. c  o m

    serialized.remove("articleID");
    normalizeField(serialized, "title");
    normalizeField(serialized, "body");
    normalizeField(serialized, "highlightedText");
    normalizeField(serialized, "authorEmailAddress");
    normalizeField(serialized, "authorName");

    serialized.remove("competingInterestBody");
    serialized.add("competingInterestStatement", context.serialize(competingInterestStatement));
    return serialized;
}

From source file:org.ambraproject.rhino.view.comment.CommentOutputView.java

License:Open Source License

@Override
public JsonElement serialize(JsonSerializationContext context) {
    JsonObject serialized = serializeBase(context, comment, competingInterestStatement);

    serialized.add("parentArticle", context.serialize(parentArticle));
    serialized.add("replyTreeSize", context.serialize(replyTreeSize));
    serialized.add("mostRecentActivity", context.serialize(mostRecentActivity));
    serialized.add("replies", context.serialize(replies));
    return serialized;
}

From source file:org.ambraproject.rhino.view.journal.ArticleListView.java

License:Open Source License

@Override
public JsonObject serialize(JsonSerializationContext context) {
    JsonObject serialized = context.serialize(getIdentity()).getAsJsonObject();
    serialized.addProperty("title", articleList.getDisplayName());

    if (!excludeArticleMetadata) {
        List<ArticleRevisionView> articleViews = Lists.transform(articleList.getArticles(),
                articleFactory::getLatestRevisionView);
        serialized.add("articles", context.serialize(articleViews));
    }//from  w  w  w .  ja  v a 2 s  .  co  m
    return serialized;
}

From source file:org.ambraproject.rhino.view.journal.IssueOutputView.java

License:Open Source License

@Override
public JsonElement serialize(JsonSerializationContext context) {
    JsonObject serialized = new JsonObject();
    serialized.addProperty("doi", issue.getDoi());
    serialized.addProperty("displayName", issue.getDisplayName());
    serialized.add("parentVolume", context.serialize(factory.volumeOutputViewFactory.getView(parentVolume)));

    Article imageArticle = issue.getImageArticle();
    if (imageArticle != null) {
        JsonObject serializedImageArticle = new JsonObject();
        String figureImageDoi = getIssueImageFigureDoi(factory.articleCrudService, imageArticle);

        serializedImageArticle.addProperty("doi", imageArticle.getDoi());
        serializedImageArticle.addProperty("figureImageDoi", figureImageDoi);
        serialized.add("imageArticle", serializedImageArticle);
    }//w w w.  ja va  2  s  .c om

    return serialized;
}

From source file:org.apache.abdera2.activities.io.gson.SimpleAdapter.java

License:Apache License

public JsonElement serialize(T t, Type type, JsonSerializationContext context) {
    return context.serialize(serialize(t));
}