Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
maureenorea-clores committed Sep 20, 2024
1 parent 2e61ffc commit ba88975
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
3 changes: 3 additions & 0 deletions dependency_check_suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
<vulnerabilityName>CVE-2021-22569</vulnerabilityName>
<vulnerabilityName>CVE-2022-3171</vulnerabilityName>
<vulnerabilityName>CVE-2022-3509</vulnerabilityName>
<vulnerabilityName>CVE-2024-7254</vulnerabilityName>
<vulnerabilityName>CVE-2024-7254</vulnerabilityName>
</suppress>
<suppress until="2024-12-31Z">
<notes><![CDATA[
Expand Down Expand Up @@ -106,5 +108,6 @@
<vulnerabilityName>CVE-2021-22569</vulnerabilityName>
<vulnerabilityName>CVE-2022-3171</vulnerabilityName>
<vulnerabilityName>CVE-2022-3510</vulnerabilityName>
<vulnerabilityName>CVE-2024-7254</vulnerabilityName>
</suppress>
</suppressions>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.rakuten.tech.mobile.inappmessaging.runtime.utils.InAppLogger
import java.lang.reflect.Type

internal class CustomJsonDeserializer : JsonDeserializer<CustomJson> {

override fun deserialize(json: JsonElement?, typeOfT: Type?, context: JsonDeserializationContext?): CustomJson {
val jsonObject = json?.asJsonObject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,20 @@ internal data class Message(
return tooltip
}

@SuppressWarnings("TooGenericExceptionCaught")
fun getCustomJsonData(): CustomJson? {
if (!RmcHelper.isRmcIntegrated() || customJson == null || customJson.entrySet().isEmpty()) {
return null
}
if (customJsonData == null) {
val gson = GsonBuilder()
.registerTypeAdapter(CustomJson::class.java, CustomJsonDeserializer())
.create()
customJsonData = gson.fromJson(customJson, CustomJson::class.java)
try {
val gson = GsonBuilder()
.registerTypeAdapter(CustomJson::class.java, CustomJsonDeserializer())
.create()
customJsonData = gson.fromJson(customJson, CustomJson::class.java)
} catch (_: Exception) {
InAppLogger(TAG).debug("getCustomJsonData - invalid customJson format")
}
}
return customJsonData
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.rakuten.tech.mobile.inappmessaging.runtime.data.responses.ping

import com.google.gson.JsonParser
import com.rakuten.tech.mobile.inappmessaging.runtime.RmcHelper
import com.rakuten.tech.mobile.inappmessaging.runtime.data.customjson.Background
import com.rakuten.tech.mobile.inappmessaging.runtime.data.customjson.CustomJson
import com.rakuten.tech.mobile.inappmessaging.runtime.data.customjson.PushPrimer
import com.rakuten.tech.mobile.inappmessaging.runtime.data.enums.InAppMessageType
Expand Down Expand Up @@ -310,7 +311,7 @@ class MessageCustomJsonSpec {
val campaign = TestDataHelper.createDummyMessage(
customJson = JsonParser.parseString("""{"pushPrimer": true}""").asJsonObject,
)
campaign.getCustomJsonData() shouldBeEqualTo null
campaign.getCustomJsonData()?.pushPrimer shouldBeEqualTo null
}

@Test
Expand Down Expand Up @@ -340,4 +341,14 @@ class MessageCustomJsonSpec {
)
campaign.getCustomJsonData() shouldBeEqualTo CustomJson(pushPrimer = PushPrimer(button = 1))
}

@Test
fun `should map CustomJson data even if there is a feature key with invalid attribute`() {
val campaign = TestDataHelper.createDummyMessage(
customJson = JsonParser.parseString(
"""{ "pushPrimer": { "button": "abcdef" }, "background": { "opacity": 0.6 } }""",
).asJsonObject,
)
campaign.getCustomJsonData() shouldBeEqualTo CustomJson(background = Background(opacity = 0.6f))
}
}

0 comments on commit ba88975

Please sign in to comment.