Skip to content

Commit 4c94a01

Browse files
brismithersjinliu9508
authored andcommitted
Update PropertiesModel's deserialization of tags to not use Model.initializeFromJson.
1 parent 7e6fd64 commit 4c94a01

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/common/modeling/Model.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ open class Model(
105105
Float::class.java, java.lang.Float::class.java -> data[property] = jsonObject.getDouble(property).toFloat()
106106
Int::class.java, java.lang.Integer::class.java -> data[property] = jsonObject.getInt(property)
107107
Boolean::class.java, java.lang.Boolean::class.java -> data[property] = jsonObject.getBoolean(property)
108+
String::class.java, java.lang.String::class.java -> data[property] = jsonObject.getString(property)
108109
else -> data[property] = jsonObject.get(property)
109110
}
110111
}

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/properties/PropertiesModel.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ class PropertiesModel : Model() {
9191
override fun createModelForProperty(property: String, jsonObject: JSONObject): Model? {
9292
if (property == ::tags.name) {
9393
val model = MapModel<String>(this, ::tags.name)
94-
model.initializeFromJson(jsonObject)
94+
for (key in jsonObject.keys()) {
95+
model.setStringProperty(key, jsonObject.getString(key))
96+
}
9597
return model
9698
}
9799

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.onesignal.user.internal.properties
2+
3+
import com.onesignal.common.putJSONObject
4+
import io.kotest.core.spec.style.FunSpec
5+
import io.kotest.matchers.shouldBe
6+
import io.kotest.runner.junit4.KotestTestRunner
7+
import org.json.JSONObject
8+
import org.junit.runner.RunWith
9+
10+
@RunWith(KotestTestRunner::class)
11+
class PropertiesModelTests : FunSpec({
12+
13+
test("successfully initializes varying tag names") {
14+
/* Given */
15+
val varyingTags = JSONObject()
16+
.putJSONObject(PropertiesModel::tags.name) {
17+
it.put("value", "data1")
18+
.put("isEmpty", "data2")
19+
.put("object", "data3")
20+
.put("1", "data4")
21+
.put("false", "data5")
22+
.put("15.7", "data6")
23+
}
24+
val propertiesModel = PropertiesModel()
25+
26+
/* When */
27+
propertiesModel.initializeFromJson(varyingTags)
28+
val tagsModel = propertiesModel.tags
29+
30+
/* Then */
31+
tagsModel["value"] shouldBe "data1"
32+
tagsModel["isEmpty"] shouldBe "data2"
33+
tagsModel["object"] shouldBe "data3"
34+
tagsModel["1"] shouldBe "data4"
35+
tagsModel["false"] shouldBe "data5"
36+
tagsModel["15.7"] shouldBe "data6"
37+
}
38+
})

0 commit comments

Comments
 (0)