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

2.9.2版本,asResponse<Int>()方法,泛型为基本类型时,使用Gson解析,报IllegalArgumentException异常,其它版本没问题 #399

Closed
liujingxing opened this issue Aug 23, 2022 · 3 comments

Comments

@liujingxing
Copy link
Owner

java.lang.IllegalArgumentException
    at com.google.gson.internal.$Gson$Preconditions.checkArgument($Gson$Preconditions.java:46)
    at com.google.gson.internal.$Gson$Types.checkNotPrimitive($Gson$Types.java:480)
    at com.google.gson.internal.$Gson$Types$ParameterizedTypeImpl.<init>($Gson$Types.java:502)
    at com.google.gson.internal.$Gson$Types.canonicalize($Gson$Types.java:116)
    at com.google.gson.reflect.TypeToken.<init>(TypeToken.java:75)
    at com.google.gson.reflect.TypeToken.get(TypeToken.java:309)
    at com.google.gson.Gson.fromJson(Gson.java:1056)
    at com.google.gson.Gson.fromJson(Gson.java:1016)
    at com.google.gson.Gson.fromJson(Gson.java:959)
    at rxhttp.wrapper.converter.GsonConverter.convert(GsonConverter.java:62)
    at rxhttp.wrapper.utils.Converter.convert(Converter.kt:45)
    at rxhttp.wrapper.utils.Converter.convertTo(Converter.kt:26)
    at rxhttp.wrapper.utils.Converter.convertTo(Converter.kt:21)
    at com.example.httpsender.parser.ResponseParser.onParse(ResponseParser.kt:44)
    at rxhttp.wrapper.param.ObservableParser$SyncParserObserver.onNext(ObservableParser.java:102)
    at rxhttp.wrapper.param.ObservableParser$SyncParserObserver.onNext(ObservableParser.java:52)
    at rxhttp.wrapper.param.ObservableCallEnqueue$HttpDisposable.onResponse(ObservableCallEnqueue.java:79)
    at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:920)
@liujingxing liujingxing changed the title 2.9.2版本,asResponse<Int>()方法,泛型为基本类型时,报IllegalArgumentException异常,其它版本没问题 2.9.2版本,asResponse<Int>()方法,泛型为基本类型时,使用Gson解析,报IllegalArgumentException异常,其它版本没问题 Aug 23, 2022
@liujingxing
Copy link
Owner Author

liujingxing commented Aug 24, 2022

经详细测试后发现,Java环境下的asResponse(Class<T>)方法,传入基本类型,如:asResponse(int.class),只要用Gson解析,任意版本皆可复现此问题,当前可传入包装类型规避此问题,如:asResponse(Integer.class)

@liujingxing
Copy link
Owner Author

liujingxing commented Aug 24, 2022

原因:Gson遇到ParameterizedType类型,会校验其actualTypeArguments数据,如果是基本数据类型,则抛出java.lang.IllegalArgumentException异常

@liujingxing
Copy link
Owner Author

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