Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JakeWoki opened this issue Nov 7, 2017 · 0 comments
Open

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

JakeWoki opened this issue Nov 7, 2017 · 0 comments

Comments

@JakeWoki
Copy link

JakeWoki commented Nov 7, 2017

@AutoValue
public abstract class Result<T> {

    public abstract int code();
    public abstract String error();
    public abstract T data();

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

}

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant