com.google.gson.JsonIOException: Abstract classes can't be instantiated! Register an InstanceCreator or a TypeAdapter for this type.
- Dominant language
- Java
- Stars
- 24.2k
- Forks
- 4.5k
- Avg merge
- 6d 4h
- Merged PRs (30d)
- 12
Description
# Gson version
'2.10.1'
# Java / Android version
JDK 17
Android Android Studio Flamingo | 2022.2.1
# Used tools
- [ ] Maven; version:
- [ ] Gradle; version:
- [ ] ProGuard (attach the configuration file please); version:
- [ ] ...
# Description
When we convert json string to Model class it gives error related to adapter. I just updated android studio to latest version it works in older version.
## Expected behavior
It should convert json string to Model class.
## Actual behavior
It throws an error.
# Reproduction steps
1. ...
2. ...
# Exception stack trace
```
W com.google.gson.JsonIOException: Abstract classes can't be instantiated! Register an InstanceCreator or a TypeAdapter for this type. Class name: com.xxx.xxx.data.pojo.other.GeneralResponse
2023-04-24 16:30:49.897 23084-23084 System.err com.xxx.xxx W at com.google.gson.internal.ConstructorConstructor$3.construct(ConstructorConstructor.java:136)
2023-04-24 16:30:49.897 23084-23084 System.err com.xxx.xxx W at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$FieldReflectionAdapter.createAccumulator(ReflectiveTypeAdapterFactory.java:427)
2023-04-24 16:30:49.897 23084-23084 System.err com.xxx.xxx W at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:383)
2023-04-24 16:30:49.898 23084-23084 System.err com.xxx.xxx W at com.google.gson.Gson.fromJson(Gson.java:1227)
2023-04-24 16:30:49.898 23084-23084 System.err com.xxx.xxx W at com.google.gson.Gson.fromJson(Gson.java:1137)
2023-04-24 16:30:49.898 23084-23084 System.err com.xxx.xxx W at com.google.gson.Gson.fromJson(Gson.java:1047)
2023-04-24 16:30:49.898 23084-23084 System.err com.xxx.xxx W at com.google.gson.Gson.fromJson(Gson.java:982)
2023-04-24 16:30:49.898 23084-23084 System.err com.xxx.xxx W at com.xxx.xxx.data.repository.BaseRepository.checkSuccess(BaseRepository.kt:8)
2023-04-24 16:30:49.898 23084-23084 System.err com.xxx.xxx W at com.xxx.xxx.data.repository.ApiRepository.login(ApiRepository.kt:51)
2023-04-24 16:30:49.898 23084-23084 System.err com.xxx.xxx W at com.xxx.xxx.data.repository.ApiRepository$login$1.invokeSuspend(ApiRepository.kt:0)
2023-04-24 16:30:49.898 23084-23084 System.err com.xxx.xxx W at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
2023-04-24 16:30:49.898 23084-23084 System.err com.xxx.xxx W at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
2023-04-24 16:30:49.898 23084-23084 System.err com.xxx.xxx W at android.os.Handler.handleCallback(Handler.java:938)
2023-04-24 16:30:49.899 23084-23084 System.err com.xxx.xxx W at android.os.Handler.dispatchMessage(Handler.java:99)
2023-04-24 16:30:49.899 23084-23084 System.err com.xxx.xxx W at android.os.Looper.loop(Looper.java:223)
2023-04-24 16:30:49.899 23084-23084 System.err com.xxx.xxx W at android.app.ActivityThread.main(ActivityThread.java:7656)
2023-04-24 16:30:49.899 23084-23084 System.err com.xxx.xxx W at java.lang.reflect.Method.invoke(Native Method)
2023-04-24 16:30:49.899 23084-23084 System.err com.xxx.xxx W at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
2023-04-24 16:30:49.899 23084-23084 System.err com.xxx.xxx W at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
```
Contributor guide
Assessment
This issue has not been assessed yet.