diff --git a/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/common/modeling/Model.kt b/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/common/modeling/Model.kt index 9b4e245727..5b82420850 100644 --- a/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/common/modeling/Model.kt +++ b/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/common/modeling/Model.kt @@ -105,6 +105,7 @@ open class Model( Float::class.java, java.lang.Float::class.java -> data[property] = jsonObject.getDouble(property).toFloat() Int::class.java, java.lang.Integer::class.java -> data[property] = jsonObject.getInt(property) Boolean::class.java, java.lang.Boolean::class.java -> data[property] = jsonObject.getBoolean(property) + String::class.java, java.lang.String::class.java -> data[property] = jsonObject.getString(property) else -> data[property] = jsonObject.get(property) } } diff --git a/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/properties/PropertiesModel.kt b/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/properties/PropertiesModel.kt index 7000afd0c8..83697ab1c0 100644 --- a/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/properties/PropertiesModel.kt +++ b/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/properties/PropertiesModel.kt @@ -91,7 +91,9 @@ class PropertiesModel : Model() { override fun createModelForProperty(property: String, jsonObject: JSONObject): Model? { if (property == ::tags.name) { val model = MapModel(this, ::tags.name) - model.initializeFromJson(jsonObject) + for (key in jsonObject.keys()) { + model.setStringProperty(key, jsonObject.getString(key)) + } return model } diff --git a/OneSignalSDK/onesignal/core/src/test/java/com/onesignal/user/internal/properties/PropertiesModelTests.kt b/OneSignalSDK/onesignal/core/src/test/java/com/onesignal/user/internal/properties/PropertiesModelTests.kt new file mode 100644 index 0000000000..7f4ff129fc --- /dev/null +++ b/OneSignalSDK/onesignal/core/src/test/java/com/onesignal/user/internal/properties/PropertiesModelTests.kt @@ -0,0 +1,38 @@ +package com.onesignal.user.internal.properties + +import com.onesignal.common.putJSONObject +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe +import io.kotest.runner.junit4.KotestTestRunner +import org.json.JSONObject +import org.junit.runner.RunWith + +@RunWith(KotestTestRunner::class) +class PropertiesModelTests : FunSpec({ + + test("successfully initializes varying tag names") { + /* Given */ + val varyingTags = JSONObject() + .putJSONObject(PropertiesModel::tags.name) { + it.put("value", "data1") + .put("isEmpty", "data2") + .put("object", "data3") + .put("1", "data4") + .put("false", "data5") + .put("15.7", "data6") + } + val propertiesModel = PropertiesModel() + + /* When */ + propertiesModel.initializeFromJson(varyingTags) + val tagsModel = propertiesModel.tags + + /* Then */ + tagsModel["value"] shouldBe "data1" + tagsModel["isEmpty"] shouldBe "data2" + tagsModel["object"] shouldBe "data3" + tagsModel["1"] shouldBe "data4" + tagsModel["false"] shouldBe "data5" + tagsModel["15.7"] shouldBe "data6" + } +})