gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-android] 10/10: Don't crash on and show unknown events


From: gnunet
Subject: [taler-wallet-android] 10/10: Don't crash on and show unknown events
Date: Thu, 30 Jan 2020 18:40:18 +0100

This is an automated email from the git hooks/post-receive script.

torsten-grote pushed a commit to branch master
in repository wallet-android.

commit c20a7945f2b37863264c3b9bdcc85454018bd4cd
Author: Torsten Grote <address@hidden>
AuthorDate: Wed Jan 22 09:30:27 2020 -0300

    Don't crash on and show unknown events
    
    Also don't crash on unexpected properties
---
 app/src/main/java/net/taler/wallet/WalletViewModel.kt     |  5 ++++-
 .../main/java/net/taler/wallet/history/HistoryEvent.kt    |  7 ++++++-
 app/src/main/res/values/strings.xml                       |  1 +
 .../java/net/taler/wallet/history/HistoryEventTest.kt     | 15 +++++++++++++++
 4 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/app/src/main/java/net/taler/wallet/WalletViewModel.kt 
b/app/src/main/java/net/taler/wallet/WalletViewModel.kt
index bc8c7e2..ad41e77 100644
--- a/app/src/main/java/net/taler/wallet/WalletViewModel.kt
+++ b/app/src/main/java/net/taler/wallet/WalletViewModel.kt
@@ -19,6 +19,7 @@ package net.taler.wallet
 import android.app.Application
 import android.util.Log
 import androidx.lifecycle.*
+import 
com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
 import com.fasterxml.jackson.databind.ObjectMapper
 import com.fasterxml.jackson.module.kotlin.KotlinModule
 import com.fasterxml.jackson.module.kotlin.readValue
@@ -130,7 +131,9 @@ class WalletViewModel(val app: Application) : 
AndroidViewModel(app) {
     private var currentWithdrawRequestId = 0
 
     private val walletBackendApi = WalletBackendApi(app)
-    private val mapper = ObjectMapper().registerModule(KotlinModule())
+    private val mapper = ObjectMapper()
+        .registerModule(KotlinModule())
+        .configure(FAIL_ON_UNKNOWN_PROPERTIES, false)
 
     fun init() {
         if (initialized) {
diff --git a/app/src/main/java/net/taler/wallet/history/HistoryEvent.kt 
b/app/src/main/java/net/taler/wallet/history/HistoryEvent.kt
index e2a7c7e..787b430 100644
--- a/app/src/main/java/net/taler/wallet/history/HistoryEvent.kt
+++ b/app/src/main/java/net/taler/wallet/history/HistoryEvent.kt
@@ -87,7 +87,8 @@ typealias History = ArrayList<HistoryEvent>
 @JsonTypeInfo(
     use = NAME,
     include = PROPERTY,
-    property = "type"
+    property = "type",
+    defaultImpl = HistoryUnknownEvent::class
 )
 /** missing:
 AuditorComplaintSent = "auditor-complained-sent",
@@ -136,6 +137,10 @@ abstract class HistoryEvent(
 }
 
 
+class HistoryUnknownEvent(timestamp: Timestamp) : HistoryEvent(timestamp) {
+    override val title = R.string.history_event_unknown
+}
+
 @JsonTypeName("exchange-added")
 class ExchangeAddedEvent(
     timestamp: Timestamp,
diff --git a/app/src/main/res/values/strings.xml 
b/app/src/main/res/values/strings.xml
index 17d1101..39fd3a6 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -30,6 +30,7 @@
     <string name="history_event_order_redirected">Purchase Redirected</string>
     <string name="history_event_refund">Refund</string>
     <string name="history_event_refreshed">Obtained change</string>
+    <string name="history_event_unknown">Unknown Event</string>
     <string name="history_fee_label">Fee:</string>
     <string name="history_show_all">Show All</string>
     <string name="history_reload">Reload History</string>
diff --git a/app/src/test/java/net/taler/wallet/history/HistoryEventTest.kt 
b/app/src/test/java/net/taler/wallet/history/HistoryEventTest.kt
index 9355161..361d2ec 100644
--- a/app/src/test/java/net/taler/wallet/history/HistoryEventTest.kt
+++ b/app/src/test/java/net/taler/wallet/history/HistoryEventTest.kt
@@ -441,4 +441,19 @@ class HistoryEventTest {
         assertEquals(timestamp, event.timestamp.ms)
     }
 
+    @Test
+    fun `test HistoryUnknownEvent`() {
+        val json = """{
+            "type": "does not exist",
+            "timestamp": {
+              "t_ms": $timestamp
+            },
+            "eventId": 
"does-not-exist;898724XGQ1GGMZB4WY3KND582NSP74FZ60BX0Y87FF81H0FJ8XD0"
+          }""".trimIndent()
+        val event: HistoryEvent = mapper.readValue(json)
+
+        assertEquals(HistoryUnknownEvent::class.java, event.javaClass)
+        assertEquals(timestamp, event.timestamp.ms)
+    }
+
 }

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]