diff --git a/ktoml-core/src/commonMain/kotlin/com/akuleshov7/ktoml/tree/nodes/tables/TomlTable.kt b/ktoml-core/src/commonMain/kotlin/com/akuleshov7/ktoml/tree/nodes/tables/TomlTable.kt index 05615dd..1bffecc 100644 --- a/ktoml-core/src/commonMain/kotlin/com/akuleshov7/ktoml/tree/nodes/tables/TomlTable.kt +++ b/ktoml-core/src/commonMain/kotlin/com/akuleshov7/ktoml/tree/nodes/tables/TomlTable.kt @@ -76,7 +76,7 @@ public class TomlTable( // Todo: Option to explicitly define super tables? // Todo: Support dotted key-value pairs (i.e. a.b.c.d = 7) - val firstChild = children.first() + val firstChild = children.firstOrNull() ?: return if (isExplicit(firstChild) && type == TableType.PRIMITIVE) { emitter.writeHeader() diff --git a/ktoml-core/src/commonTest/kotlin/com/akuleshov7/ktoml/encoders/ArrayEncoderTest.kt b/ktoml-core/src/commonTest/kotlin/com/akuleshov7/ktoml/encoders/ArrayEncoderTest.kt index 554fe9b..0900c92 100644 --- a/ktoml-core/src/commonTest/kotlin/com/akuleshov7/ktoml/encoders/ArrayEncoderTest.kt +++ b/ktoml-core/src/commonTest/kotlin/com/akuleshov7/ktoml/encoders/ArrayEncoderTest.kt @@ -18,7 +18,7 @@ class ArrayEncoderTest { expectedToml = "a = [ ]" ) } - + @Test fun simpleArrayTest() { @Serializable @@ -128,4 +128,18 @@ class ArrayEncoderTest { expectedToml = "a = { b = [ 1, 2, 3 ] }" ) } + + @Test + fun emptyArrayInTableTest(){ + @Serializable + data class EmbeddedData(val data: String = "embedded data") + + @Serializable + data class EmptyListData(val content: List = listOf() ) + + assertEncodedEquals( + value = EmptyListData(), + expectedToml = "" + ) + } }