Example usage for com.google.gson JsonElement isJsonObject

List of usage examples for com.google.gson JsonElement isJsonObject

Introduction

In this page you can find the example usage for com.google.gson JsonElement isJsonObject.

Prototype

public boolean isJsonObject() 

Source Link

Document

provides check for verifying if this element is a Json object or not.

Usage

From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.DiffHunkParser.java

License:Apache License

@Override
public DiffHunk apply(JsonElement jsonElement) {
    if (jsonElement == null || !jsonElement.isJsonObject()) {
        return null;
    }/*  w w w .ja  v a 2s  . c  o  m*/
    JsonObject json = jsonElement.getAsJsonObject();

    return new DiffHunk(json.get("destinationLine").getAsInt(), json.get("destinationSpan").getAsInt(),
            listParser(diffSegmentParser()).apply(json.get("segments")), json.get("sourceLine").getAsInt(),
            json.get("sourceSpan").getAsInt(), json.get("truncated").getAsBoolean());
}

From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.DiffLineParser.java

License:Apache License

@Override
public DiffLine apply(JsonElement jsonElement) {

    if (jsonElement == null || !jsonElement.isJsonObject()) {
        return null;
    }//from w  w  w  . ja  v  a2s .  c om
    JsonObject json = jsonElement.getAsJsonObject();

    return new DiffLine(json.get("destination").getAsInt(), json.get("line").getAsString(),
            json.get("source").getAsInt(), json.get("truncated").getAsBoolean());
}

From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.DiffParser.java

License:Apache License

@Override
public Diff apply(JsonElement jsonElement) {

    if (jsonElement == null || !jsonElement.isJsonObject()) {
        return null;
    }//from w  w w  .j a v  a 2s  .c o m

    JsonObject json = jsonElement.getAsJsonObject();

    return new Diff(pathParser().apply(json.get("destination").getAsJsonObject()),
            listParser(diffHunkParser()).apply(json.get("hunks")),
            json.get("source").isJsonNull() ? null : pathParser().apply(json.get("source").getAsJsonObject()),
            json.has("binary") && json.get("binary").getAsBoolean(), json.get("truncated").getAsBoolean());
}

From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.DiffSegmentParser.java

License:Apache License

@Override
public DiffSegment apply(JsonElement jsonElement) {
    if (jsonElement == null || !jsonElement.isJsonObject()) {
        return null;
    }// w  w w  . j a  v  a2s . c o  m

    JsonObject json = jsonElement.getAsJsonObject();
    return new DiffSegment(listParser(diffLineParser()).apply(json.get("lines")),
            DiffSegmentType.valueOf(json.get("type").getAsString()), json.get("truncated").getAsBoolean());
}

From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.MinimalCommitParser.java

License:Apache License

@Override
public MinimalCommit apply(JsonElement jsonElement) {
    if (jsonElement == null || !jsonElement.isJsonObject()) {
        return null;
    }/*from   www .java 2s. c om*/
    JsonObject json = jsonElement.getAsJsonObject();

    return new MinimalCommit(json.get("id").getAsString(), json.get("displayId").getAsString());
}

From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.PathParser.java

License:Apache License

@Override
public Path apply(JsonElement json) {
    if (json == null || !json.isJsonObject()) {
        return null;
    }//from   ww w .  j av a  2s .c o  m
    JsonObject jsonObject = json.getAsJsonObject();
    JsonArray array = jsonObject.getAsJsonArray("components");
    String[] components = new String[array.size()];
    Iterator<JsonElement> it = array.iterator();
    int i = 0;
    while (it.hasNext()) {
        components[i++] = it.next().getAsString();
    }

    return new Path(components);
}

From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.PermittedOperationsParser.java

License:Apache License

@Override
public PermittedOperations apply(JsonElement jsonElement) {
    if (jsonElement == null || !jsonElement.isJsonObject()) {
        return null;
    }/*from www .  j av a2  s.  c om*/
    JsonObject json = jsonElement.getAsJsonObject();
    return new PermittedOperations(json.get("editable").getAsBoolean(), json.get("deletable").getAsBoolean());
}

From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.PullRequestActivityParser.java

License:Apache License

@Override
public PullRequestActivity apply(JsonElement jsonElement) {
    if (jsonElement == null || !jsonElement.isJsonObject()) {
        return null;
    }//from   ww w. ja va 2s.c o m
    JsonObject json = jsonElement.getAsJsonObject();

    PullRequestActivityActionType actionType = PullRequestActivityActionType
            .valueOf(json.get("action").getAsString());
    if (actionType == PullRequestActivityActionType.COMMENTED) {
        return new PullRequestCommentActivity(json.get("id").getAsLong(),
                new Date(json.get("createdDate").getAsLong()), userParser().apply(json.getAsJsonObject("user")),
                pullRequestId, json.get("commentAction").getAsString(),
                commentParser().apply(json.getAsJsonObject("comment")),
                commentAnchorParser().apply(json.getAsJsonObject("commentAnchor")),
                json.has("diff") ? diffParser().apply(json.getAsJsonObject("diff")) : null

        );
    } else if (actionType == PullRequestActivityActionType.RESCOPED) {
        List<Commit> added = new ArrayList<>();
        List<Commit> removed = new ArrayList<>();
        if (json.has("added")) {
            added = getCommits(json.get("added").getAsJsonObject());
        }
        if (json.has("removed")) {
            removed = getCommits(json.get("removed").getAsJsonObject());
        }

        return new PullRequestRescopedActivity(json.get("id").getAsLong(),
                new Date(json.get("createdDate").getAsLong()), userParser().apply(json.getAsJsonObject("user")),
                pullRequestId, json.get("fromHash").getAsString(), json.get("previousFromHash").getAsString(),
                json.get("previousToHash").getAsString(), json.get("toHash").getAsString(), added, removed);

    } else if (actionType == PullRequestActivityActionType.MERGED) {
        return new PullRequestMergedActivity(json.get("id").getAsLong(),
                new Date(json.get("createdDate").getAsLong()), userParser().apply(json.getAsJsonObject("user")),
                pullRequestId);
    } else if (actionType == PullRequestActivityActionType.APPROVED) {
        return new PullRequestApprovedActivity(json.get("id").getAsLong(),
                new Date(json.get("createdDate").getAsLong()), userParser().apply(json.getAsJsonObject("user")),
                pullRequestId);
    } else if (actionType == PullRequestActivityActionType.DECLINED) {
        return new PullRequestDeclinedActivity(json.get("id").getAsLong(),
                new Date(json.get("createdDate").getAsLong()), userParser().apply(json.getAsJsonObject("user")),
                pullRequestId);
    } else if (actionType == PullRequestActivityActionType.UNAPPROVED) {
        return new PullRequestUnapprovedActivity(json.get("id").getAsLong(),
                new Date(json.get("createdDate").getAsLong()), userParser().apply(json.getAsJsonObject("user")),
                pullRequestId);
    } else if (actionType == PullRequestActivityActionType.OPENED) {
        return new PullRequestOpenedActivity(json.get("id").getAsLong(),
                new Date(json.get("createdDate").getAsLong()), userParser().apply(json.getAsJsonObject("user")),
                pullRequestId);
    } else if (actionType == PullRequestActivityActionType.REOPENED) {
        return new PullRequestReOpenedActivity(json.get("id").getAsLong(),
                new Date(json.get("createdDate").getAsLong()), userParser().apply(json.getAsJsonObject("user")),
                pullRequestId);
    } else if (actionType == PullRequestActivityActionType.UPDATED) {
        return new PullRequestUpdatedActivity(json.get("id").getAsLong(),
                new Date(json.get("createdDate").getAsLong()), userParser().apply(json.getAsJsonObject("user")),
                pullRequestId);
    } else if (actionType == PullRequestActivityActionType.REVIEWED) {
        return new PullRequestReviewedActivity(json.get("id").getAsLong(),
                new Date(json.get("createdDate").getAsLong()), userParser().apply(json.getAsJsonObject("user")),
                pullRequestId);
    } else
        throw new RuntimeException("cannot parse action:" + actionType);

}

From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.PullRequestBranchParser.java

License:Apache License

@Override
public PullRequestBranch apply(JsonElement json) {
    if (json == null || !json.isJsonObject()) {
        return null;
    }//  w  w  w. ja  v  a2  s.c  o m
    JsonObject jsonObject = json.getAsJsonObject();
    JsonObject repository = jsonObject.getAsJsonObject("repository");
    JsonObject project = repository.getAsJsonObject("project");
    return new PullRequestBranch(jsonObject.get("id").getAsString(), repository.get("slug").getAsString(),
            optionalJsonString(repository, "name"), project.get("key").getAsString());
}

From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.PullRequestChangeParser.java

License:Apache License

@Override
public PullRequestChange apply(JsonElement jsonElement) {
    if (jsonElement == null || !jsonElement.isJsonObject()) {
        return null;
    }/*w w  w  . j a  v a2s .co m*/
    JsonObject json = jsonElement.getAsJsonObject();
    String selfUrl = null;
    if (json.has("links")) {
        selfUrl = linkParser().apply(json.getAsJsonObject("links").get("self").getAsJsonArray().get(0))
                .getHref();
    }
    return new PullRequestChange(json.get("contentId").getAsString(), optionalJsonString(json, "fromContentId"),
            pathParser().apply(json.getAsJsonObject("path")),
            pathParser().apply(json.getAsJsonObject("srcPath")),
            FileChangeType.valueOf(json.get("type").getAsString()), json.get("executable").getAsBoolean(),
            json.get("percentUnchanged").getAsInt(), NodeType.valueOf(json.get("nodeType").getAsString()),
            json.get("executable").getAsBoolean(), selfUrl);

}