Skip to content

getParcelable returning null when it shouldnt #9

@radimjanda754

Description

@radimjanda754

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions