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

KotlinXSerializationMapper decodes lists to be size 1 always #911

Closed
Niro opened this issue Feb 25, 2024 · 1 comment · Fixed by #913
Closed

KotlinXSerializationMapper decodes lists to be size 1 always #911

Niro opened this issue Feb 25, 2024 · 1 comment · Fixed by #913

Comments

@Niro
Copy link
Contributor

Niro commented Feb 25, 2024

Current implementation relies on kotlinx.serialization.descriptors.SerialDescriptor#getElementsCount. According to documentation it will be always 1.

    /**
     * The number of elements this descriptor describes, besides from the class itself.
     * [elementsCount] describes the number of **semantic** elements, not the number
     * of actual fields/properties in the serialized form, even though they frequently match.
     *
     * For example, for the following class
     * `class Complex(val real: Long, val imaginary: Long)` the corresponding descriptor
     * and the serialized form both have two elements, while for `class IntList : ArrayList<Int>()`
     * the corresponding descriptor has a single element (`IntDescriptor`, the type of list element),
     * but from zero up to `Int.MAX_VALUE` values in the serialized form.
     */
    @ExperimentalSerializationApi
    public val elementsCount: Int

As a result when Decoder tries to decode list field it gives up after first value. From screenshot below you can see that from underlying storage 16 elements was read but with current implementation it will contain only one element after decoding document to Kotlin data class.
image

@Niro
Copy link
Contributor Author

Niro commented Feb 25, 2024

Opened PR with a fix and test enhancement for this case

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

Successfully merging a pull request may close this issue.

1 participant