Skip to content

Commit 9de5ddb

Browse files
committed
Send back json string of config specs from rulesUpdatedCallback
1 parent 1f4ed96 commit 9de5ddb

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/main/kotlin/com/statsig/sdk/StatsigServer.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.statsig.sdk
22

33
import com.google.gson.Gson
4+
import com.google.gson.GsonBuilder
5+
import com.google.gson.ToNumberPolicy
46
import kotlinx.coroutines.CoroutineExceptionHandler
57
import kotlinx.coroutines.CoroutineScope
68
import kotlinx.coroutines.CoroutineStart
@@ -171,6 +173,8 @@ private class StatsigServerImpl(serverSecret: String, private val options: Stats
171173
}
172174
}
173175

176+
private val gson = GsonBuilder().setObjectToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE).create()
177+
174178
override val errorBoundary = ErrorBoundary(serverSecret, options)
175179
private val coroutineExceptionHandler =
176180
CoroutineExceptionHandler { _, ex ->
@@ -204,7 +208,7 @@ private class StatsigServerImpl(serverSecret: String, private val options: Stats
204208
return
205209
}
206210
try {
207-
val configString = configSpecs.toString()
211+
val configString = gson.toJson(configSpecs)
208212
options.rulesUpdatedCallback?.accept(configString)
209213
} catch (e: Exception) {}
210214
}

src/test/java/com/statsig/sdk/StatsigE2ETest.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ class StatsigE2ETest {
376376
bootstrapValues = downloadConfigSpecsResponse,
377377
rulesUpdatedCallback = {
378378
bootstrap_callback_count++
379+
val specs = gson.fromJson(it, APIDownloadedConfigs::class.java)
380+
assert(gson.toJson(specs) == gson.toJson(gson.fromJson(downloadConfigSpecsResponse, APIDownloadedConfigs::class.java)))
379381
}
380382
).apply {
381383
api = server.url("/v1").toString()
@@ -385,7 +387,11 @@ class StatsigE2ETest {
385387
} else {
386388
options = StatsigOptions(
387389
bootstrapValues = downloadConfigSpecsResponse,
388-
rulesUpdatedCallback = { bootstrap_callback_count++ }
390+
rulesUpdatedCallback = {
391+
bootstrap_callback_count++
392+
val specs = gson.fromJson(it, APIDownloadedConfigs::class.java)
393+
assert(gson.toJson(specs) == gson.toJson(gson.fromJson(downloadConfigSpecsResponse, APIDownloadedConfigs::class.java)))
394+
}
389395
).apply {
390396
api = server.url("/v1").toString()
391397
}

0 commit comments

Comments
 (0)