File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed
main/kotlin/kotlinx/serialization/hocon
test/kotlin/kotlinx/serialization/hocon Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -145,7 +145,7 @@ public sealed class Hocon(
145
145
146
146
}
147
147
148
- private inner class ConfigReader (val conf : Config , private val poly : Boolean = false ) : ConfigConverter<String>() {
148
+ private inner class ConfigReader (val conf : Config , private val isPolymorph : Boolean = false ) : ConfigConverter<String>() {
149
149
private var ind = - 1
150
150
151
151
override fun decodeElementIndex (descriptor : SerialDescriptor ): Int {
@@ -162,7 +162,7 @@ public sealed class Hocon(
162
162
if (parentName.isEmpty()) childName else " $parentName .$childName "
163
163
164
164
override fun SerialDescriptor.getTag (index : Int ): String {
165
- return if (! poly ) composeName(
165
+ return if (! isPolymorph ) composeName(
166
166
currentTagOrNull.orEmpty(),
167
167
getConventionElementName(index, useConfigNamingConvention)
168
168
) else getElementName(index)
@@ -216,7 +216,7 @@ public sealed class Hocon(
216
216
override fun beginStructure (descriptor : SerialDescriptor ): CompositeDecoder =
217
217
when {
218
218
// Polymorph should always be object-like I believe?
219
- descriptor.kind.objLike -> ConfigReader (conf, true )
219
+ descriptor.kind.objLike -> ConfigReader (conf, isPolymorph = true )
220
220
else -> this
221
221
}
222
222
Original file line number Diff line number Diff line change @@ -23,6 +23,9 @@ class HoconPolymorphismTest {
23
23
data class AnnotatedTypeChild (@SerialName(" my_type" ) val type : String ) : Sealed(3 )
24
24
}
25
25
26
+ @Serializable
27
+ data class SealedContainer (val sealed : Collection <Sealed >)
28
+
26
29
@Serializable
27
30
data class CompositeClass (var sealed : Sealed )
28
31
@@ -102,4 +105,25 @@ class HoconPolymorphismTest {
102
105
serializer = Sealed .serializer(),
103
106
)
104
107
}
108
+
109
+ @Test
110
+ fun testCollectionContainer () {
111
+ objectHocon.assertStringFormAndRestored(
112
+ expected = """
113
+ sealed = [
114
+ { type = annotated_type_child, my_type = override, intField = 3 }
115
+ { type = object }
116
+ { type = data_class, name = testDataClass, intField = 1 }
117
+ ]
118
+ """ .trimIndent(),
119
+ original = SealedContainer (
120
+ listOf (
121
+ Sealed .AnnotatedTypeChild (type = " override" ),
122
+ Sealed .ObjectChild ,
123
+ Sealed .DataClassChild (name = " testDataClass" ),
124
+ )
125
+ ),
126
+ serializer = SealedContainer .serializer(),
127
+ )
128
+ }
105
129
}
You can’t perform that action at this time.
0 commit comments