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

网络请求返回的 data 为 null 时奔溃 #46

Closed
STGing opened this issue Dec 8, 2020 · 1 comment
Closed

网络请求返回的 data 为 null 时奔溃 #46

STGing opened this issue Dec 8, 2020 · 1 comment

Comments

@STGing
Copy link

STGing commented Dec 8, 2020

首先感谢大佬的框架,集成到项目中挺方便的。最近在使用中碰到一些问题,咨询一下。
1.我这边返回的数据格式就是那种有 code,message,data 的样子
2.所以我网络请求一般都是用自动脱壳的方式,但是这边有个问题是,当返回的数据 data 是 null的时候,app就会奔溃
报错信息:
java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter it

此处的 it 是请求成功后,在 parseState(resultState,{ 这里的it })
3. 用不脱壳的方式应该是ok的,因为自己可以处理进行判空呀啥的。但是所有的请求接口,总会有的接口有时候返回 null 有时候有数据,这样的话岂不是所有的接口都需要使用不脱壳的方式嘛。
4.咨询一下大佬有没有更好的解决方式,或者怎么弄会更合理

@hegaojian
Copy link
Owner

在写Retrofit请求配置的时候设置返回值泛型可为空 例如:

 @GET("xxx")
  suspend fun xxx(): ApiResponse<Any?>

@STGing STGing closed this as completed Dec 9, 2020
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

2 participants