Search in sources :

Example 1 with Listing

use of rxreddit.model.Listing in project RxReddit by damien5314.

the class CommentDeserializer method deserialize.

@Override
public Listing deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject o = json.getAsJsonObject();
    String kind = o.get("kind").getAsString();
    Listing listing;
    switch(kind) {
        case "t1":
            listing = context.deserialize(json, Comment.class);
            return listing;
        case "more":
            listing = context.deserialize(json, CommentStub.class);
            return listing;
        default:
            return null;
    }
}
Also used : Comment(rxreddit.model.Comment) Listing(rxreddit.model.Listing) CommentStub(rxreddit.model.CommentStub) JsonObject(com.google.gson.JsonObject)

Aggregations

JsonObject (com.google.gson.JsonObject)1 Comment (rxreddit.model.Comment)1 CommentStub (rxreddit.model.CommentStub)1 Listing (rxreddit.model.Listing)1