Проблема с преобразованием из json в object

Я хочу сделать класс для сохранений объектов. Но возникают проблемы при upcast. Я пробовал изменить правила proguard но это не решило проблемы

handleError: com.google.gson.internal.LinkedTreeMap cannot be cast to com.uialert.mapbirds.data.network.payload.response.user.UserResponse
com.google.gson.internal.LinkedTreeMap cannot be cast to com.uialert.mapbirds.data.network.payload.response.user.UserResponse
java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to com.uialert.mapbirds.data.network.payload.response.use
    at com.uialert.mapbirds.model.user.UserModel.getInfoMe(UserModel.kt:27)
    at com.uialert.mapbirds.start.SplashScreenViewModel$postTestRequest$1.invokeSuspend(SplashScreenViewModel.kt:22)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:367)
    at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30)
    at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:25)
    at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:110)
    at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126)
    at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56)
    at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
    at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)
    at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1)
    at com.uialert.mapbirds.start.SplashScreenViewModel.postTestRequest(SplashScreenViewModel.kt:20)
    at com.uialert.mapbirds.start.SplashScreen$onCreate$1.invokeSuspend(SplashScreen.kt:40)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    at androidx.lifecycle.DispatchQueue.drainQueue(DispatchQueue.kt:75)
    at androidx.lifecycle.DispatchQueue.resume(DispatchQueue.kt:54)
    at androidx.lifecycle.LifecycleController$observer$1.onStateChanged(LifecycleController.kt:40)
    at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354)
    at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:265)
    at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:307)
    at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:148)
    at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:134)
    at androidx.lifecycle.ReportFragment.dispatch(ReportFragment.java:68)
    at androidx.lifecycle.ReportFragment$LifecycleCallbacks.onActivityPostCreated(ReportFragment.java:178)
    at android.app.Activity.dispatchActivityPostCreated(Activity.java:1330)
    at android.app.Activity.performCreate(Activity.java:8016)
    at android.app.Activity.performCreate(Activity.java:7990)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3589)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3780)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2251)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:233)
    at android.app.ActivityThread.main(ActivityThread.java:8068)

                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)
class CacheController<E>(val context: Context, val type: CacheType) {
    private val sp: SharedPreferences = context.getSharedPreferences("pref", Context.MODE_PRIVATE)
    private val spe: SharedPreferences.Editor = sp.edit()
    private val gson: Gson = Gson()

    private fun save(id: String, e: E) {
        spe.putString(getIdName(id), gson.toJson(e))
        spe.apply()
    }

    fun get(id: String): E? {
        val load = sp.getString(getIdName(id), null)
        return gson.fromJson(load, genericType())
    }

    private fun genericType(): Type = object : TypeToken<E>() {}.type
}

Ответы (0 шт):