Protein icon indicating copy to clipboard operation
Protein copied to clipboard

请教个问题,autoValue配gson怎么用泛型?

Open JakeWoki opened this issue 7 years ago • 0 comments

@AutoValue
public abstract class Result<T> {

    public abstract int status();
    public abstract String message();
    public abstract T data();

    public static <T> TypeAdapter<Result<T>> typeAdapter(Gson gson, TypeToken<T> typeToken) {
        return new AutoValue_Result.GsonTypeAdapter(gson, typeToken).nullSafe();
    }

}

请求返回固定格式,这样一个泛型,请求成功是没有问题,但是失败了,返回 {"status":0,"message":"","data":""}或{"status":0,"message":""}解析都出错,这种怎么解决呢?(不使用autovalue是没有问题的)

JakeWoki avatar Nov 07 '17 07:11 JakeWoki