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

kotlinxDeserializerOf in fuel-kotlinx-serialization crashes with kotlin 1.3.70 and kotlinx.serialization 0.20.0 #720

Closed
Chubacca opened this issue Mar 9, 2020 · 10 comments · Fixed by #733

Comments

@Chubacca
Copy link

Chubacca commented Mar 9, 2020

Bug Report

Description

When using kotlin 1.3.70 and kotlinx.serialization 0.20.0, kotlinxDeserializerOf crashes on use. Kotlin 1.3.70 requires kotlinx.serialization 0.20.0.

To Reproduce

Steps to reproduce the behavior:

  1. Use kotlinxDeserializerOf
val deserializer = kotlinxDeserializerOf(JsonObject.serializer())

Expected behavior

Do not crash. Here is the stacktrace:

2020-03-09 11:51:43.626 15027-15027/com.example.test E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.test, PID: 15027
    java.lang.NoSuchFieldError: No field Companion of type Lkotlinx/serialization/json/Json$Companion; in class Lkotlinx/serialization/json/Json; or its superclasses (declaration of 'kotlinx.serialization.json.Json' appears in /data/app/com.example.test-Q10Jp2kFGAok9G4WvSYvAw==/base.apk)
        at com.example.test.app.RestClient.login(RestClient.kt:92)
        at com.example.test.LoginEmailFragment$ViewModel$login$1.invokeSuspend(LoginEmailFragment.kt:51)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedKt.resumeCancellable(Dispatched.kt:457)
        at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:26)
        at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:109)
        at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:154)
        at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:54)
        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.example.test.LoginEmailFragment$ViewModel.login(LoginEmailFragment.kt:50)
        at com.example.test.databinding.ContainerLoginEmailBindingImpl._internalCallbackOnClick(ContainerLoginEmailBindingImpl.java:390)
        at com.example.test.generated.callback.OnClickListener.onClick(OnClickListener.java:11)
        at android.view.View.performClick(View.java:6597)
        at android.view.View.performClickInternal(View.java:6574)
        at android.view.View.onKeyUp(View.java:13216)
        at android.widget.TextView.onKeyUp(TextView.java:7782)
        at android.view.KeyEvent.dispatch(KeyEvent.java:2798)
        at android.view.View.dispatchKeyEvent(View.java:12450)
        at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1896)
        at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1896)
        at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1896)
        at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1896)
        at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1896)
        at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1896)
        at com.android.internal.policy.DecorView.superDispatchKeyEvent(DecorView.java:438)
        at com.android.internal.policy.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1821)
        at android.app.Activity.dispatchKeyEvent(Activity.java:3373)
        at androidx.core.app.ComponentActivity.superDispatchKeyEvent(ComponentActivity.java:122)
        at androidx.core.view.KeyEventDispatcher.dispatchKeyEvent(KeyEventDispatcher.java:84)
        at androidx.core.app.ComponentActivity.dispatchKeyEvent(ComponentActivity.java:140)
        at com.android.internal.policy.DecorView.dispatchKeyEvent(DecorView.java:352)
        at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:5056)
        at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4922)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4443)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4496)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4462)
        at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4602)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4470)
        at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4659)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4443)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4496)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4462)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4470)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4443)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4496)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4462)

Environment

Development Machine

Complete the following information if applicable

  • OS: Mac OSX Mojave 10.14.6 (18G3020)
  • IDE: Android Studio 3.6.1
  • Fuel version: 2.2.1
  • Kotlin version: 1.3.70
  • Kotlinx.serialization version: 0.20.0

Smartphone or Emulator

Complete the following information if applicable

  • Device: Pixel 3XL
  • OS: Android 10.0
@kittinunf
Copy link
Owner

Hmm, this might be a problem of a combination of version Kotlin + Kotlin serialization. Could you try this combination and see whether this works?

kotlin = 1.3.61
kotlinSerialization = 0.14.0

@Chubacca
Copy link
Author

Those versions work fine (it's what I was using before). I upgraded to kotlin 1.3.70, which isn't compatible with kolinxSerialization 0.14.0, so I upgraded that to 0.20.0. Then these problems started occurring (so rolling back is a temporary solution).

@kittinunf
Copy link
Owner

#722 I tried to update core version in this PR. I will try to bump to 1.3.70 and 0.20.0 🙇

@Chubacca
Copy link
Author

FWIW I checked and it only breaks on specifically JsonObject.serializer(). If I use my own custom @Serializable classes it works fine.

@kittinunf
Copy link
Owner

Hmm that is a bit concerning. So, if you provide a custom serializable adapter it would be just fine?

@Chubacca
Copy link
Author

@kittinunf

So it's not actually the custom serializable adapter - it's the use of the Json.plain default (I think).

So this crashes:
kotlinxDeserializerOf(JsonObject.serializer())

But this does not:
kotlinxDeserializerOf(JsonObject.serializer(), Json(JsonConfiguration.Stable))

So it may be that just updating the libraries will fix the problem.

Hope that helps. Thanks!

@arosenb2
Copy link

arosenb2 commented Apr 3, 2020

I just ran into this same issue.

Json.plain (which is provided internally for json parsing in responseObject<T>() for the fuel-kotlinx-serialization package) is deprecated in kotlinx-serialization-runtime:0.20.0.

@arosenb2
Copy link

arosenb2 commented Apr 3, 2020

As a around until there's an update to the package, I ended up fixing by explicitly passing in a valid json configuration:

val (_, _, result) = Fuel
    .request(ApiRouter.InvokeSomeRequest())
    .responseObject<ApiResponse>(json = Json(JsonConfiguration.Stable))

@kittinunf
Copy link
Owner

kittinunf commented Apr 4, 2020

@arosenb2 and @Chubacca Thanks you both for reporting this! Would you two mind to check my PR? Here? #733 If that works, I will quickly publish a fix version for this.

@Chubacca
Copy link
Author

Chubacca commented Apr 5, 2020

Looks good. Maybe you could make a shared Json(JsonConfiguration.Stable) object so you're not creating a new object every time?

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

Successfully merging a pull request may close this issue.

3 participants