summaryrefslogtreecommitdiff
path: root/formats/hocon/src/test/kotlin/kotlinx/serialization/hocon/HoconPolymorphismTest.kt
diff options
context:
space:
mode:
Diffstat (limited to 'formats/hocon/src/test/kotlin/kotlinx/serialization/hocon/HoconPolymorphismTest.kt')
-rw-r--r--formats/hocon/src/test/kotlin/kotlinx/serialization/hocon/HoconPolymorphismTest.kt48
1 files changed, 48 insertions, 0 deletions
diff --git a/formats/hocon/src/test/kotlin/kotlinx/serialization/hocon/HoconPolymorphismTest.kt b/formats/hocon/src/test/kotlin/kotlinx/serialization/hocon/HoconPolymorphismTest.kt
index db038e70..1dbc1f90 100644
--- a/formats/hocon/src/test/kotlin/kotlinx/serialization/hocon/HoconPolymorphismTest.kt
+++ b/formats/hocon/src/test/kotlin/kotlinx/serialization/hocon/HoconPolymorphismTest.kt
@@ -24,6 +24,12 @@ class HoconPolymorphismTest {
}
@Serializable
+ data class SealedCollectionContainer(val sealed: Collection<Sealed>)
+
+ @Serializable
+ data class SealedMapContainer(val sealed: Map<String, Sealed>)
+
+ @Serializable
data class CompositeClass(var sealed: Sealed)
@@ -102,4 +108,46 @@ class HoconPolymorphismTest {
serializer = Sealed.serializer(),
)
}
+
+ @Test
+ fun testCollectionContainer() {
+ objectHocon.assertStringFormAndRestored(
+ expected = """
+ sealed = [
+ { type = annotated_type_child, my_type = override, intField = 3 }
+ { type = object }
+ { type = data_class, name = testDataClass, intField = 1 }
+ ]
+ """.trimIndent(),
+ original = SealedCollectionContainer(
+ listOf(
+ Sealed.AnnotatedTypeChild(type = "override"),
+ Sealed.ObjectChild,
+ Sealed.DataClassChild(name = "testDataClass"),
+ )
+ ),
+ serializer = SealedCollectionContainer.serializer(),
+ )
+ }
+
+ @Test
+ fun testMapContainer() {
+ objectHocon.assertStringFormAndRestored(
+ expected = """
+ sealed = {
+ "annotated_type_child" = { type = annotated_type_child, my_type = override, intField = 3 }
+ "object" = { type = object }
+ "data_class" = { type = data_class, name = testDataClass, intField = 1 }
+ }
+ """.trimIndent(),
+ original = SealedMapContainer(
+ mapOf(
+ "annotated_type_child" to Sealed.AnnotatedTypeChild(type = "override"),
+ "object" to Sealed.ObjectChild,
+ "data_class" to Sealed.DataClassChild(name = "testDataClass"),
+ )
+ ),
+ serializer = SealedMapContainer.serializer(),
+ )
+ }
}