1
1
package com.statsig.sdk
2
2
3
- import com.google.gson.Gson
4
3
import com.google.gson.annotations.SerializedName
5
- import com.google.gson.reflect.TypeToken
6
4
7
5
internal data class ClientInitializeResponse (
8
6
@SerializedName(" feature_gates" ) var feature_gates : Map <String , ClientConfig >,
@@ -16,10 +14,20 @@ internal data class ClientInitializeResponse(
16
14
@SerializedName(" hash_used" ) var hash_used : String ,
17
15
@SerializedName(" user_hash" ) var user_hash : String ,
18
16
) {
17
+
19
18
fun toMap (): Map <String , Any > {
20
- val gson = Gson ()
21
- val json = gson.toJson(this )
22
- return gson.fromJson(json, object : TypeToken <Map <String , Any >>() {}.type)
19
+ val map = mutableMapOf<String , Any >()
20
+ map[" feature_gates" ] = feature_gates.mapValues { (_, config) -> config.toMap() }
21
+ map[" dynamic_configs" ] = dynamic_configs.mapValues { (_, config) -> config.toMap() }
22
+ map[" layer_configs" ] = layer_configs.mapValues { (_, config) -> config.toMap() }
23
+ map[" sdkParams" ] = sdkParams
24
+ map[" has_updates" ] = has_updates
25
+ map[" time" ] = time
26
+ map[" generator" ] = generator
27
+ map[" evaluated_keys" ] = evaluated_keys
28
+ map[" hash_used" ] = hash_used
29
+ map[" user_hash" ] = user_hash
30
+ return map
23
31
}
24
32
25
33
fun isEmpty (): Boolean {
@@ -41,7 +49,24 @@ internal data class ClientConfig(
41
49
@SerializedName(" explicit_parameters" ) var explicitParameters : Array <String >? = null ,
42
50
@SerializedName(" is_in_layer" ) var isInLayer : Boolean? = null ,
43
51
@SerializedName(" is_device_based" ) var isDeviceBased : Boolean? = null ,
44
- )
52
+ ) {
53
+ fun toMap (): Map <String , Any ?> {
54
+ val map = mutableMapOf<String , Any ?>()
55
+ map[" name" ] = name
56
+ map[" value" ] = value
57
+ map[" rule_id" ] = ruleID
58
+ map[" secondary_exposures" ] = secondaryExposures
59
+ if (undelegatedSecondaryExposures != null ) map[" undelegated_secondary_exposures" ] = undelegatedSecondaryExposures
60
+ if (group != null ) map[" group" ] = group
61
+ if (allocatedExperimentName != null ) map[" allocated_experiment_name" ] = allocatedExperimentName
62
+ if (isUserInExperiment != null ) map[" is_user_in_experiment" ] = isUserInExperiment
63
+ if (isExperimentActive != null ) map[" is_experiment_active" ] = isExperimentActive
64
+ if (explicitParameters != null ) map[" explicit_parameters" ] = explicitParameters
65
+ if (isInLayer != null ) map[" is_in_layer" ] = isInLayer
66
+ if (isDeviceBased != null ) map[" is_device_based" ] = isDeviceBased
67
+ return map
68
+ }
69
+ }
45
70
46
71
internal class ClientInitializeFormatter (
47
72
private val specStore : SpecStore ,
@@ -158,6 +183,7 @@ internal class ClientInitializeFormatter(
158
183
val evalResult = ConfigEvaluation ()
159
184
evalFun(user, configSpec, evalResult)
160
185
val hashedName = hashName(configName)
186
+
161
187
val result = ClientConfig (
162
188
hashedName,
163
189
" value" to false ,
0 commit comments