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

getParcelable returning null when it shouldnt #9

Open
radimjanda754 opened this issue Jul 1, 2024 · 2 comments
Open

getParcelable returning null when it shouldnt #9

radimjanda754 opened this issue Jul 1, 2024 · 2 comments

Comments

@radimjanda754
Copy link

radimjanda754 commented Jul 1, 2024

Hello after upgrading from 0.5.1 to 0.7.1 I get many errors that serializable is null, when trying to access it after some decoding , but it shouldnt be null, Im not sure what am I doing wrong.

Here is example of the code:

@ExperimentalSerializationApi
inline fun <reified T> Bundle.putParcelableTest(
    key: String, value: T, parcelable: com.chrynan.parcelable.core.Parcelable = com.chrynan.parcelable.core.Parcelable.Default
) {
    val encoded = parcelable.encodeToBundle(value = value)
    putBundle(key, encoded)

    // This works
    val bundle = getBundle(key)
    val decoded: T = parcelable.decodeFromBundle(requireNotNull(bundle))

    // Returns null
    val decoded2: T? = getParcelable(key, parcelable = com.chrynan.parcelable.core.Parcelable.Default)

    // This works
    val decoded3: T? = getParcelableTest(key, parcelable = com.chrynan.parcelable.core.Parcelable.Default)
}

@ExperimentalSerializationApi
inline fun <reified T : Any> Bundle.getParcelableTest(
    key: String,
    flags: Int = 0,
    parcelable: com.chrynan.parcelable.core.Parcelable = com.chrynan.parcelable.core.Parcelable.Default
): T? {
    val bundle = getBundle(key)
    return parcelable.decodeFromBundle(requireNotNull(bundle))
}

The getParcelable bundle extension doesnt work here and returns null, however I realized that if I create my own extension that is reified T : Any instead of just reified T then it starts to work again. But this is not the only function which I have problem with, so Im not sure what am I doing wrong.

Copy link

github-actions bot commented Jul 1, 2024

Welcome and thanks for contributing! Make sure to leave a detailed explanation of the issue. For a faster response time, consider boosting your issue.

@chRyNaN
Copy link
Owner

chRyNaN commented Aug 27, 2024

I will try and take a deeper look to see what is going on when I have spare time. In the meantime, try the latest version 0.9.0.

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