Example usage for com.google.gson JsonElement getAsJsonObject

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

Introduction

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

Prototype

public JsonObject getAsJsonObject() 

Source Link

Document

convenience method to get this element as a JsonObject .

Usage

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

License:Apache License

@Override
public Commit apply(JsonElement jsonElement) {

    if (jsonElement == null || !jsonElement.isJsonObject()) {
        return null;
    }/*  www .ja  v  a  2  s .  c o  m*/
    JsonObject json = jsonElement.getAsJsonObject();

    return new Commit(json.get("id").getAsString(), json.get("displayId").getAsString(),
            json.get("author").getAsJsonObject().get("name").getAsString(),
            json.get("author").getAsJsonObject().get("emailAddress").getAsString(),
            json.get("authorTimestamp").getAsLong(), json.get("message").getAsString(),
            listParser(minimalCommitParser()).apply(json.get("parents")));
}

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;
    }//from  w  w  w  . ja v  a 2s  . c  om
    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 ww .j av a2 s  .co  m*/
    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. ja va  2 s  .  co 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;
    }//from   w w w  . jav  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.ErrorParser.java

License:Apache License

@Override
public BitBucketError apply(JsonElement jsonElement) {
    JsonObject json = jsonElement.getAsJsonObject();
    return new BitBucketError(json.get("message").getAsString(), ParserUtil.optionalJsonString(json, "context"),
            ParserUtil.optionalJsonString(json, "exceptionName"));
}

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

License:Apache License

@Override
public List<BitBucketError> apply(JsonElement input) {
    JsonObject jsonObject = input.getAsJsonObject();
    return listParser(errorParser()).apply(jsonObject.get("error"));
}

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

License:Apache License

@Override
public Link apply(JsonElement jsonElement) {
    JsonObject json = jsonElement.getAsJsonObject();
    String href = optionalJsonString(json, linkName);
    String name = optionalJsonString(json, textName);
    return new Link(href, name);
}

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;
    }/*  w w w . ja va  2 s  .  c o m*/
    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.PageParser.java

License:Apache License

@Override
public Page<T> apply(JsonElement jsonElement) {
    JsonObject json = jsonElement.getAsJsonObject();
    List<T> values = Parsers.listParser(valueParser).apply(json.getAsJsonArray("values"));

    return new Page<>(json.get("size").getAsInt(), json.get("limit").getAsInt(),
            optionalJsonBoolean(json, "isLastPage"), json.get("start").getAsInt(),
            (int) optionalJsonLong(json, "nextPageStart"), values);
}