diff options
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/form')
| -rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/form/Form.kt | 32 |
1 files changed, 6 insertions, 26 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/Form.kt b/src/main/kotlin/pl/treksoft/kvision/form/Form.kt index 62d22de9..323d0e1e 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/Form.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/Form.kt @@ -23,6 +23,7 @@ package pl.treksoft.kvision.form import kotlinx.serialization.KSerializer import kotlinx.serialization.Mapper +import kotlinx.serialization.decode import kotlinx.serialization.json.JSON import kotlinx.serialization.serializer import pl.treksoft.kvision.form.upload.Upload @@ -44,27 +45,6 @@ internal data class FieldParams<in F : FormControl>( ) /** - * A wrapper for a Map with a custom containsKey method implementation. - * Used with kotlinx.serialization Mapper. - */ -private class FormMapWrapper<out V>(private val map: Map<String, V>) : Map<String, V> { - override fun equals(other: Any?): Boolean = map == other - override fun hashCode(): Int = map.hashCode() - override fun toString(): String = map.toString() - override val size: Int get() = map.size - override fun isEmpty(): Boolean = map.isEmpty() - override fun containsKey(key: String): Boolean = - if (key.indexOf('.') != -1) map.containsKey(key) else - !(map.containsKey("$key.time") || map.containsKey("$key.size")) - - override fun containsValue(value: @UnsafeVariance V): Boolean = map.containsValue(value) - override fun get(key: String): V? = map[key] - override val keys: Set<String> get() = map.keys - override val values: Collection<V> get() = map.values - override val entries: Set<Map.Entry<String, V>> get() = map.entries -} - -/** * The form definition class. Can be used directly or indirectly inside a [FormPanel]. * * @constructor Creates a form with a given modelFactory function @@ -94,9 +74,9 @@ class Form<K : Any>(private val panel: FormPanel<K>? = null, private val seriali listOf(entry.key to entry.value, "${entry.key}.size" to list.size) + list.mapIndexed { index, kFile -> listOf( - "${entry.key}.${index + 1}.name" to kFile.name, - "${entry.key}.${index + 1}.size" to kFile.size, - "${entry.key}.${index + 1}.content" to kFile.content + "${entry.key}.${index}.name" to kFile.name, + "${entry.key}.${index}.size" to kFile.size, + "${entry.key}.${index}.content" to kFile.content ) }.flatten() } ?: listOf() @@ -104,8 +84,8 @@ class Form<K : Any>(private val panel: FormPanel<K>? = null, private val seriali else -> listOf(entry.key to entry.value) } }.toMap() - val mapper = Mapper.InNullableMapper(FormMapWrapper(map)) - mapper.read(serializer) + val mapper = Mapper.InNullableMapper(map) + mapper.decode(serializer) } } |
