package com.tenlionsoft.baselib.core.network.response;


import com.google.gson.internal.$Gson$Types;

import org.json.JSONException;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * Created by Xuer on 2017/3/8.
 */
public abstract class GsonResponseHandler<T> implements ResponseHandler {
    Type mType;

    public GsonResponseHandler() {
        Type myclass = getClass().getGenericSuperclass();    //反射获取带泛型的class
        if (myclass instanceof Class) {
            throw new RuntimeException("Missing type parameter.");
        }
        ParameterizedType parameter = (ParameterizedType) myclass;      //获取所有泛型
        mType = $Gson$Types.canonicalize(parameter.getActualTypeArguments()[0]);  //将泛型转为type
    }

    public final Type getType() {
        return mType;
    }

    public abstract void onSuccess(int statusCode, T response) throws JSONException;

    @Override
    public void onProgress(long currentBytes, long totalBytes) {

    }
}
