Search in sources :

Example 1 with PaginationData

use of org.edx.mobile.model.PaginationData in project edx-app-android by edx.

the class JsonPageDeserializer method deserialize.

@Override
public Page<?> deserialize(JsonElement json, final Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    final List<?> list = context.deserialize(json.getAsJsonObject().get("results"), new ParameterizedType() {

        public Type getRawType() {
            return List.class;
        }

        public Type getOwnerType() {
            return null;
        }

        public Type[] getActualTypeArguments() {
            return ((ParameterizedType) typeOfT).getActualTypeArguments();
        }
    });
    JsonElement paginationJson = json.getAsJsonObject().get("pagination");
    if (null == paginationJson || paginationJson.isJsonNull()) {
        paginationJson = json;
    }
    final PaginationData paginationData = context.deserialize(paginationJson, PaginationData.class);
    return new Page<>(paginationData, list);
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) PaginationData(org.edx.mobile.model.PaginationData) JsonElement(com.google.gson.JsonElement) Page(org.edx.mobile.model.Page)

Aggregations

JsonElement (com.google.gson.JsonElement)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 Page (org.edx.mobile.model.Page)1 PaginationData (org.edx.mobile.model.PaginationData)1