Skip to content

Iterable<T> is not serializable as a property #151

@Whathecode

Description

@Whathecode

Is there a specific reason why Iterable<T> cannot be serialized when it is a property, but it can be when it is serialized individually? When the type is specified as List<T> instead of Iterable<T> serialization does succeed.

The following tests all pass on v0.5.1:

@Test
fun `can serialize Iterable`()
{
    val iterable: Iterable<Int> = listOf( 1 )
    val serialized = JSON.stringify( PolymorphicSerializer, iterable )
}

@Serializable
data class ContainsIterable( val list: Iterable<Int> )

@Test
fun `cannot serialize Iterable as a property`()
{
    val iterableList = ContainsIterable( listOf( 1 ) )
    assertFailsWith<NoSuchMethodError>
    {
        val serialized = JSON.stringify( iterableList )
    }
}

@Serializable
data class ContainsList( val list: List<Int> )

@Test
fun `can serialize List as a property`()
{
    val list = ContainsList( listOf( 1 ) )
    val serialized = JSON.stringify( list )
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions