kotlinx.serialization icon indicating copy to clipboard operation
kotlinx.serialization copied to clipboard

kotlinx.serialization.SerializationException: Serializer for class 'JsonObject' is not found. (OnePlus)

Open AndiMiko opened this issue 3 years ago • 4 comments

Describe the bug

kotlinx.serialization.SerializationException: Serializer for class 'JsonObject' is not found. Mark the class @Serializable or provide the serializer explicitly.

To Reproduce

Issue occurs on following line:

    val json = Json.decodeFromString<JsonObject>(jwsToken.content())

The odd thing is it does not occur on debug builds and in doesn't on my Pixel 3a. I have tested two OnePlus devices (5 and 3T) and on those phones the exception is thrown (in Prod builds only).

Environment

  • Kotlin version: 1.4.10
  • Library version: 1.0.1
  • Kotlin platforms: Android
  • Gradle version: 4.0.2
  • Other relevant context: OnePlus devices

I have checked the JsonObject and it is obviously annotated with @Serializable(JsonObjectSerializer::class). My suspicion is that on OnePlus devices it somehow references a different JsonObject which is not annotated. Any idea or workaround for this?

AndiMiko avatar Mar 26 '21 22:03 AndiMiko

can be related to https://github.com/Kotlin/kotlinx.serialization/issues/1355

zepurplez avatar Mar 29 '21 06:03 zepurplez

https://github.com/Kotlin/kotlinx.serialization#android try to add proguard rules, it is necessary for correct working

kuFEAR avatar Apr 03 '21 17:04 kuFEAR

Will try that. But how come that it may work on one device model but not on the other? Since proguard is done at compile time I would expect the same behavior?

AndiMiko avatar Apr 04 '21 22:04 AndiMiko

@AndiMiko Did applying the ProGuard rules resolve this for you? Without it, I would expect it to fail either way when ProGuard or R8 runs. Also note that the ProGuard rules have changed since this issue was created.

It is indeed odd it did work on your Pixel 3a. Perhaps a mistake during testing?

Whathecode avatar Apr 12 '22 14:04 Whathecode