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

Parcelize serializable data is broken #5

Closed
MichalKlusak opened this issue Feb 3, 2023 · 5 comments
Closed

Parcelize serializable data is broken #5

MichalKlusak opened this issue Feb 3, 2023 · 5 comments

Comments

@MichalKlusak
Copy link

MichalKlusak commented Feb 3, 2023

Describe the bug
When I'm trying to transfer Serializable data through Bundle, I use methods putParcelable and getParcelable to parcelize it but the result data is broken.

To Reproduce
Params:

@Serializable
data class Params(val intro: Boolean)
val params = Params(true)
val bundle = Bundle()
bundle.putParcelable("key", params)
bundle.getParcelable("key")

Result behavior
Params(false)

Expected behavior
Params(true)

val params = Params(false)
val bundle = Bundle()
bundle.putParcelable("key", params)
bundle.getParcelable("key")

Result behavior
null

Expected behavior
Params(false)

Additional context
Serialization-parcelable - 0.5.1 (version 0.5.0 works fine)
Kotlin - 1.7.20
Kotlin-serialization - 1.4.1

@github-actions
Copy link

github-actions bot commented Feb 3, 2023

Welcome and thanks for contributing! Make sure to leave a detailed explanation of the issue.

@MichalKlusak MichalKlusak changed the title Serializable broken Parcelize serializable data is broken Feb 3, 2023
@chRyNaN
Copy link
Owner

chRyNaN commented Feb 9, 2023

I was able to reproduce the issue. I'm not positive about the cause, but it seemed to be an incorrect function call. It was resolved after the changes made in the following commit where I removed the AndroidParceler class: 92fd90c. I will try and write some tests to make sure that this issue doesn't occur again. The fix will be released in the next version.

@chRyNaN
Copy link
Owner

chRyNaN commented Feb 11, 2023

The issue has to do with the Parcel(ByteArray) constructor function implementation for the Android target. The decodeFromParcel function was updated previously to get the parcel.toByteArray() from the parcel parameter and create a new Parcel using that constructor function. Then that Parcel was decoded with a ParcelDecoder. This was added to help some issue with the ByteArrayParcel implementation for other platforms, but it seems that it broke the Android usage. I will investigate further and ensure that both implementations work.

chRyNaN pushed a commit that referenced this issue Feb 11, 2023
@chRyNaN
Copy link
Owner

chRyNaN commented Feb 11, 2023

The issue had to do with the Android implementation of the Parcel(ByteArray) calling setDataPosition(0) and the above mentioned use of creating a new Parcel from the provided parcel in the Parcelable.decodeFromParcel function. The Parcelable.encodeToBundle/Parcelable.decodeFromBundle have to internally manage a size and magic numbers set inside the android.os.Parcel class. Because of this, the size should have been set to 8 (two four byte int values were set). Instead of hardcoding this, since it is TBD which component should be responsible for setting that, I think removing the wrapper creation of a new parcel in the decodeFromParcel function is the solution and seems to work. However, we should be on the lookout for issues on other Kotlin targets.

@chRyNaN
Copy link
Owner

chRyNaN commented Feb 11, 2023

Resolved with release 0.6.0 (10): https://github.com/chRyNaN/serialization-parcelable/releases/tag/0.6.0

@chRyNaN chRyNaN closed this as completed Feb 11, 2023
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