@@ -145,7 +145,7 @@ public sealed class Hocon(
145
145
146
146
}
147
147
148
- private inner class ConfigReader (val conf : Config ) : ConfigConverter<String>() {
148
+ private inner class ConfigReader (val conf : Config , private val poly : Boolean = false ) : ConfigConverter<String>() {
149
149
private var ind = - 1
150
150
151
151
override fun decodeElementIndex (descriptor : SerialDescriptor ): Int {
@@ -161,8 +161,12 @@ public sealed class Hocon(
161
161
private fun composeName (parentName : String , childName : String ) =
162
162
if (parentName.isEmpty()) childName else " $parentName .$childName "
163
163
164
- override fun SerialDescriptor.getTag (index : Int ): String =
165
- composeName(currentTagOrNull.orEmpty(), getConventionElementName(index, useConfigNamingConvention))
164
+ override fun SerialDescriptor.getTag (index : Int ): String {
165
+ return if (! poly) composeName(
166
+ currentTagOrNull.orEmpty(),
167
+ getConventionElementName(index, useConfigNamingConvention)
168
+ ) else getElementName(index)
169
+ }
166
170
167
171
override fun decodeNotNullMark (): Boolean {
168
172
// Tag might be null for top-level deserialization
@@ -206,6 +210,28 @@ public sealed class Hocon(
206
210
}
207
211
}
208
212
213
+ private inner class PolymorphConfigReader (private val conf : Config ) : ConfigConverter<String>() {
214
+ private var ind = - 1
215
+
216
+ override fun beginStructure (descriptor : SerialDescriptor ): CompositeDecoder =
217
+ when {
218
+ // Polymorph should always be object-like I believe?
219
+ descriptor.kind.objLike -> ConfigReader (conf, true )
220
+ else -> this
221
+ }
222
+
223
+ override fun SerialDescriptor.getTag (index : Int ): String = getElementName(index)
224
+
225
+ override fun decodeElementIndex (descriptor : SerialDescriptor ): Int {
226
+ ind++
227
+ return if (ind >= descriptor.elementsCount) DECODE_DONE else ind
228
+ }
229
+
230
+ override fun <E > getValueFromTaggedConfig (tag : String , valueResolver : (Config , String ) -> E ): E {
231
+ return valueResolver(conf, tag)
232
+ }
233
+ }
234
+
209
235
private inner class ListConfigReader (private val list : ConfigList ) : ConfigConverter<Int>() {
210
236
private var ind = - 1
211
237
@@ -216,6 +242,7 @@ public sealed class Hocon(
216
242
217
243
override fun beginStructure (descriptor : SerialDescriptor ): CompositeDecoder =
218
244
when {
245
+ descriptor.kind is PolymorphicKind -> PolymorphConfigReader ((list[currentTag] as ConfigObject ).toConfig())
219
246
descriptor.kind.listLike -> ListConfigReader (list[currentTag] as ConfigList )
220
247
descriptor.kind.objLike -> ConfigReader ((list[currentTag] as ConfigObject ).toConfig())
221
248
descriptor.kind == StructureKind .MAP -> MapConfigReader (list[currentTag] as ConfigObject )
0 commit comments