You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 )
}
The text was updated successfully, but these errors were encountered:
There is no specific serializer for Iterable. Your first test works because you've explicitly specified serializer for iterable as Polymorphic, you could do the same for property with annotation @Serializable(with=...).
Personally I think Iterable is a too broad interface to be serializable, because while it can be an usual list (and why don't use List instead), it also can be lazy and/or infinite stream of elements.
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 asList<T>
instead ofIterable<T>
serialization does succeed.The following tests all pass on v0.5.1:
The text was updated successfully, but these errors were encountered: