aboutsummaryrefslogtreecommitdiff
path: root/cashier/src
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2022-06-01 13:31:38 +0200
committerFlorian Dold <florian@dold.me>2022-06-01 13:31:38 +0200
commita229b33997842a66295aa4d8dfb5dab6d2f769df (patch)
tree72031a742800ceaae337f04377fb052c91cc2068 /cashier/src
parent1ef7ae77475f5dd99401a992a92f6c622b29c0a6 (diff)
downloadtaler-android-a229b33997842a66295aa4d8dfb5dab6d2f769df.tar.gz
taler-android-a229b33997842a66295aa4d8dfb5dab6d2f769df.tar.bz2
taler-android-a229b33997842a66295aa4d8dfb5dab6d2f769df.zip
use new annotation for polymorphic serialization
Diffstat (limited to 'cashier/src')
-rw-r--r--cashier/src/main/java/net/taler/cashier/MainViewModel.kt10
-rw-r--r--cashier/src/main/java/net/taler/cashier/config/ConfigManager.kt3
2 files changed, 10 insertions, 3 deletions
diff --git a/cashier/src/main/java/net/taler/cashier/MainViewModel.kt b/cashier/src/main/java/net/taler/cashier/MainViewModel.kt
index 1c819b9..2196e78 100644
--- a/cashier/src/main/java/net/taler/cashier/MainViewModel.kt
+++ b/cashier/src/main/java/net/taler/cashier/MainViewModel.kt
@@ -28,6 +28,7 @@ import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.serialization.kotlinx.json.json
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
+import kotlinx.serialization.json.Json
import net.taler.cashier.HttpHelper.makeJsonGetRequest
import net.taler.cashier.config.ConfigManager
import net.taler.cashier.withdraw.WithdrawManager
@@ -45,8 +46,12 @@ class MainViewModel(private val app: Application) : AndroidViewModel(app) {
retryOnConnectionFailure(true)
}
}
+ expectSuccess = true
install(ContentNegotiation) {
- json()
+ json(Json {
+ encodeDefaults = false
+ ignoreUnknownKeys = true
+ })
}
}
val configManager = ConfigManager(app, viewModelScope, httpClient)
@@ -72,7 +77,8 @@ class MainViewModel(private val app: Application) : AndroidViewModel(app) {
"debit" -> false
else -> throw AmountParserException("Unexpected credit_debit_indicator: $creditDebitIndicator")
}
- BalanceResult.Success(SignedAmount(positive, Amount.fromJSONString(balanceAmount)))
+ BalanceResult.Success(SignedAmount(positive,
+ Amount.fromJSONString(balanceAmount)))
} catch (e: Exception) {
Log.e(TAG, "Error parsing balance", e)
BalanceResult.Error("Invalid amount:\n${response.json.toString(2)}")
diff --git a/cashier/src/main/java/net/taler/cashier/config/ConfigManager.kt b/cashier/src/main/java/net/taler/cashier/config/ConfigManager.kt
index 882348f..2fde37d 100644
--- a/cashier/src/main/java/net/taler/cashier/config/ConfigManager.kt
+++ b/cashier/src/main/java/net/taler/cashier/config/ConfigManager.kt
@@ -29,6 +29,7 @@ import androidx.security.crypto.EncryptedSharedPreferences.PrefValueEncryptionSc
import androidx.security.crypto.MasterKeys
import androidx.security.crypto.MasterKeys.AES256_GCM_SPEC
import io.ktor.client.HttpClient
+import io.ktor.client.call.body
import io.ktor.client.request.get
import io.ktor.client.request.header
import io.ktor.http.HttpHeaders.Authorization
@@ -116,7 +117,7 @@ class ConfigManager(
val url = "${config.bankUrl}/config"
Log.d(TAG, "Checking config: $url")
val configResponse = response {
- httpClient.get(url) as ConfigResponse
+ httpClient.get(url).body<ConfigResponse>()
}
if (configResponse.isFailure) {
configResponse