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

Chord unparcelizing / deserializing throws SerializationException #8

Closed
cullub opened this issue Dec 27, 2021 · 7 comments
Closed

Chord unparcelizing / deserializing throws SerializationException #8

cullub opened this issue Dec 27, 2021 · 7 comments

Comments

@cullub
Copy link
Contributor

cullub commented Dec 27, 2021

Describe the bug
When I call com.chrynan.chords.util.putChord(key, chord) to put a chord in a Bundle(), then later call bundle.getChord(key), the chords library throws a SerializationException ("Expected Json Decoder").

To Reproduce
Here's my code putting the chord in a Bundle:

MyFragment().apply {
    arguments = Bundle().apply {
        putChord(KEY_CHORD, chord)
    }
}

And here's the get:

arguments?.getChord(KEY_CHORD)

Expected behavior
The chord should be retrieved.

Desktop (please complete the following information):

  • OS: Android
  • Browser N/A
  • Version 11

Smartphone (please complete the following information):

  • Device: Emulated Pixel 4 XL API 30
  • OS: Android
  • Browser N/A
  • Version 11

Stacktrace

2021-12-27 00:37:40.111 5630-5630/com.gbros.tabslite E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.gbros.tabslite, PID: 5630
    kotlinx.serialization.SerializationException: Expected Json Decoder for com.chrynan.parcelable.core.ParcelDecoder@4761331.
        at com.chrynan.chords.model.serializer.ChordMarkerJsonSerializer.deserialize(ChordMarkerJsonSerializer.kt:36)
        at com.chrynan.chords.model.serializer.ChordMarkerJsonSerializer.deserialize(ChordMarkerJsonSerializer.kt:16)
        at kotlinx.serialization.encoding.Decoder$DefaultImpls.decodeSerializableValue(Decoding.kt:260)
        at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:16)
        at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:43)
        at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableElement(AbstractDecoder.kt:70)
        at kotlinx.serialization.encoding.CompositeDecoder$DefaultImpls.decodeSerializableElement$default(Decoding.kt:535)
        at kotlinx.serialization.internal.ListLikeSerializer.readElement(CollectionSerializers.kt:80)
        at kotlinx.serialization.internal.ListLikeSerializer.readAll(CollectionSerializers.kt:76)
        at kotlinx.serialization.internal.AbstractCollectionSerializer.merge(CollectionSerializers.kt:31)
        at kotlinx.serialization.internal.AbstractCollectionSerializer.deserialize(CollectionSerializers.kt:43)
        at kotlinx.serialization.encoding.Decoder$DefaultImpls.decodeSerializableValue(Decoding.kt:260)
        at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:16)
        at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:43)
        at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableElement(AbstractDecoder.kt:70)
        at com.chrynan.chords.model.Chord$$serializer.deserialize(Chord.kt:25)
        at com.chrynan.chords.model.Chord$$serializer.deserialize(Chord.kt:25)
        at kotlinx.serialization.encoding.Decoder$DefaultImpls.decodeSerializableValue(Decoding.kt:260)
        at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:16)
        at com.chrynan.parcelable.android.AndroidParcelableUtilsKt.decodeFromParcel(AndroidParcelableUtils.kt:63)
        at com.chrynan.parcelable.android.AndroidParceler.createFromParcel(AndroidParceler.kt:23)
        at com.chrynan.parcelable.android.AndroidParcelBundleUtilsKt.decodeFromBundle(AndroidParcelBundleUtils.kt:88)
        at com.chrynan.chords.util.ParcelableUtilsKt.getChord(ParcelableUtils.kt:104)
        at com.gbros.tabslite.ChordFragment$chord$2.invoke(ChordFragment.kt:34)
        at com.gbros.tabslite.ChordFragment$chord$2.invoke(ChordFragment.kt:34)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at com.gbros.tabslite.ChordFragment.getChord(ChordFragment.kt:34)
        at com.gbros.tabslite.ChordFragment.onCreateView(ChordFragment.kt:38)
        at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2995)
        at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:523)
        at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:261)
        at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1840)
        at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1758)
        at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1670)
        at androidx.fragment.app.BackStackRecord.commitNow(BackStackRecord.java:317)
        at androidx.viewpager2.adapter.FragmentStateAdapter.placeFragmentInViewHolder(FragmentStateAdapter.java:341)
        at androidx.viewpager2.adapter.FragmentStateAdapter.onViewAttachedToWindow(FragmentStateAdapter.java:276)
        at androidx.viewpager2.adapter.FragmentStateAdapter.onViewAttachedToWindow(FragmentStateAdapter.java:67)
        at androidx.recyclerview.widget.RecyclerView.dispatchChildAttached(RecyclerView.java:7867)
        at androidx.recyclerview.widget.RecyclerView$5.addView(RecyclerView.java:893)
        at androidx.recyclerview.widget.ChildHelper.addView(ChildHelper.java:107)
2021-12-27 00:37:40.117 5630-5630/com.gbros.tabslite E/AndroidRuntime:     at androidx.recyclerview.widget.RecyclerView$LayoutManager.addViewInt(RecyclerView.java:8902)
        at androidx.recyclerview.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:8860)
        at androidx.recyclerview.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:8848)
        at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1645)
        at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1591)
        at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:668)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4309)
        at androidx.recyclerview.widget.RecyclerView.onMeasure(RecyclerView.java:3686)
        at android.view.View.measure(View.java:25466)
        at android.view.ViewGroup.measureChild(ViewGroup.java:6928)
        at androidx.viewpager2.widget.ViewPager2.onMeasure(ViewPager2.java:498)
        at android.view.View.measure(View.java:25466)
        at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:735)
        at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:481)
        at android.view.View.measure(View.java:25466)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at android.view.View.measure(View.java:25466)
        at com.google.android.material.bottomsheet.BottomSheetBehavior.onMeasureChild(BottomSheetBehavior.java:463)
        at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:831)
        at android.view.View.measure(View.java:25466)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at android.view.View.measure(View.java:25466)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:145)
        at android.view.View.measure(View.java:25466)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at android.view.View.measure(View.java:25466)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at android.view.View.measure(View.java:25466)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
        at android.view.View.measure(View.java:25466)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at com.android.internal.policy.DecorView.onMeasure(DecorView.java:747)
        at android.view.View.measure(View.java:25466)
        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:3397)
        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:2228)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2486)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1952)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8171)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:972)
        at android.view.Choreographer.doCallbacks(Choreographer.java:796)
        at android.view.Choreographer.doFrame(Choreographer.java:731)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
2021-12-27 00:37:40.117 5630-5630/com.gbros.tabslite E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
2021-12-27 00:37:40.144 5630-5630/com.gbros.tabslite I/Process: Sending signal. PID: 5630 SIG: 9

Additional context

getChord() uses com.chrynan.parcelable and calls (eventually) ChordMarkerJsonSerializer.deserialize, but calls it with a com.chrynan.parcelable.core.ParcelDecoder. That doesn't implement JsonDecoder, so ChordMarkerJsonSerializer.kt throws a SerializationException.

For reference, I'm working on TabsLite.

@cullub
Copy link
Contributor Author

cullub commented Dec 27, 2021

Tl;DR: this might be an issue with the serialization/parcelable library, but I'm not sure so I put the issue here. Making com.chrynan.parcelable.core.ParcelDecoder implement JsonDecoder would fix the exception, but I'm not sure if that's the right solution.

@chRyNaN
Copy link
Owner

chRyNaN commented Dec 29, 2021

I converted over this library to use my serialization-parcelable library. Unfortunately, I had to leave one custom serializer due to its complexity. But it looks like the serializer internally expects everything to be in Json format, but the serialization-parcelable library does not have the model in Json format. That seems to be why you are encountering this issue. The fix is to either update the custom serializer to work with serialization-parcelable, or to drop that dependency and bring back all of the custom parcelizers.

@chRyNaN
Copy link
Owner

chRyNaN commented Dec 29, 2021

@cullub The solution was rather simple. It seems my serialization-parcelable library works well with sealed classes. So I just replaced the @Serializable(with = ChordMarkerSerializer::class) from the ChordMarker model with @Serializable and it worked for me. I added the @SerialName() annotation to each of the sub-classes of the sealed class to make sure their type property matches appropriately in a Json format, but I haven't tested this yet.

@cullub
Copy link
Contributor Author

cullub commented Dec 29, 2021

Great! @chRyNaN any chance we can get a v2.4.1 bugfix release with these changes?

@cullub
Copy link
Contributor Author

cullub commented Dec 29, 2021

As it turns out, in my code I had only been using this feature in one place, and was able to replace it with another method, but the other couple things ( #11 specifically) are still needed for my latest update

@chRyNaN
Copy link
Owner

chRyNaN commented Dec 29, 2021

@cullub Yes, I'll get another release out tonight.

@chRyNaN
Copy link
Owner

chRyNaN commented Dec 29, 2021

Version 2.4.1 (6) is released.

@chRyNaN chRyNaN closed this as completed Dec 29, 2021
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

2 participants