1717package spp.protocol.instrument.variable
1818
1919import io.vertx.codegen.annotations.DataObject
20+ import io.vertx.core.json.JsonArray
2021import io.vertx.core.json.JsonObject
2122
2223/* *
@@ -27,18 +28,31 @@ data class LiveVariableControl(
2728 val maxObjectDepth : Int? = null ,
2829 val maxObjectSize : Int? = null ,
2930 val maxCollectionLength : Int? = null ,
30- val variableTypeConfig : Map <String , LiveVariableControl > = emptyMap(),
31- val variableNameConfig : Map <String , LiveVariableControl > = emptyMap()
31+ val variableTypeConfig : Map <String , LiveVariableControlBase > = emptyMap(),
32+ val variableNameConfig : Map <String , LiveVariableControlBase > = emptyMap()
3233) {
3334 constructor (json: JsonObject ) : this (
3435 maxObjectDepth = json.getInteger(" maxObjectDepth" ),
3536 maxObjectSize = json.getInteger(" maxObjectSize" ),
3637 maxCollectionLength = json.getInteger(" maxCollectionLength" ),
37- variableTypeConfig = json.getJsonObject(" variableTypeConfig" )?.let {
38- it.associate { it.key to LiveVariableControl (it.value as JsonObject ) }
38+
39+ variableTypeConfig = json.getValue(" variableTypeConfig" )?.let {
40+ when (it) {
41+ is JsonObject -> it.associate { it.key to LiveVariableControlBase (it.value as JsonObject ) }
42+ is JsonArray -> it.map { JsonObject .mapFrom(it) }
43+ .associate { it.getString(" type" ) to LiveVariableControlBase (it.getJsonObject(" control" )) }
44+
45+ else -> throw IllegalArgumentException (" variableTypeConfig must be a JsonObject or JsonArray" )
46+ }
3947 }.orEmpty(),
40- variableNameConfig = json.getJsonObject(" variableNameConfig" )?.let {
41- it.associate { it.key to LiveVariableControl (it.value as JsonObject ) }
48+ variableNameConfig = json.getValue(" variableNameConfig" )?.let {
49+ when (it) {
50+ is JsonObject -> it.associate { it.key to LiveVariableControlBase (it.value as JsonObject ) }
51+ is JsonArray -> it.map { JsonObject .mapFrom(it) }
52+ .associate { it.getString(" type" ) to LiveVariableControlBase (it.getJsonObject(" control" )) }
53+
54+ else -> throw IllegalArgumentException (" variableTypeConfig must be a JsonObject or JsonArray" )
55+ }
4256 }.orEmpty()
4357 )
4458
0 commit comments