diff options
Diffstat (limited to 'wallet/src/main/java/net/taler')
3 files changed, 19 insertions, 21 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt index 5ca2255..693fe7e 100644 --- a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt +++ b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt @@ -32,7 +32,6 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import kotlinx.serialization.KSerializer import kotlinx.serialization.json.Json -import kotlinx.serialization.json.JsonConfiguration import net.taler.wallet.backend.WalletBackendService.Companion.MSG_COMMAND import net.taler.wallet.backend.WalletBackendService.Companion.MSG_NOTIFY import net.taler.wallet.backend.WalletBackendService.Companion.MSG_REPLY @@ -49,9 +48,9 @@ class WalletBackendApi( private val app: Application, private val notificationHandler: ((payload: JSONObject) -> Unit) ) { - private val json = Json( - JsonConfiguration.Stable.copy(ignoreUnknownKeys = true) - ) + private val json = Json { + ignoreUnknownKeys = true + } private var walletBackendMessenger: Messenger? = null private val queuedMessages = LinkedList<Message>() private val handlers = ConcurrentHashMap<Int, (isError: Boolean, message: JSONObject) -> Unit>() @@ -153,14 +152,14 @@ class WalletBackendApi( serializer: KSerializer<T>? = null, args: (JSONObject.() -> JSONObject)? = null ): WalletResponse<T> = withContext(Dispatchers.Default) { - suspendCoroutine<WalletResponse<T>> { cont -> + suspendCoroutine { cont -> sendRequest(operation, args?.invoke(JSONObject())) { isError, message -> val response = if (isError) { - val error = json.parse(WalletErrorInfo.serializer(), message.toString()) - WalletResponse.Error<T>(error) + val error = json.decodeFromString(WalletErrorInfo.serializer(), message.toString()) + WalletResponse.Error(error) } else { @Suppress("UNCHECKED_CAST") // if serializer is null, T must be Unit - val t: T = serializer?.let { json.parse(serializer, message.toString()) } ?: Unit as T + val t: T = serializer?.let { json.decodeFromString(serializer, message.toString()) } ?: Unit as T WalletResponse.Success(t) } cont.resume(response) @@ -173,11 +172,11 @@ class WalletBackendApi( mapper: ObjectMapper, noinline args: (JSONObject.() -> JSONObject)? = null ): WalletResponse<T> = withContext(Dispatchers.Default) { - suspendCoroutine<WalletResponse<T>> { cont -> + suspendCoroutine { cont -> sendRequest(operation, args?.invoke(JSONObject())) { isError, message -> val response = if (isError) { val error: WalletErrorInfo = mapper.readValue(message.toString()) - WalletResponse.Error<T>(error) + WalletResponse.Error(error) } else { val t: T = mapper.readValue(message.toString()) WalletResponse.Success(t) diff --git a/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt b/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt index ab3d42e..57ce82e 100644 --- a/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt +++ b/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt @@ -21,18 +21,17 @@ import com.fasterxml.jackson.databind.DeserializationContext import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.deser.std.StdDeserializer -import kotlinx.serialization.Decoder -import kotlinx.serialization.Encoder import kotlinx.serialization.KSerializer -import kotlinx.serialization.PrimitiveDescriptor -import kotlinx.serialization.PrimitiveKind.STRING import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import kotlinx.serialization.json.JsonInput +import kotlinx.serialization.descriptors.PrimitiveKind.STRING +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.json.JsonDecoder import kotlinx.serialization.json.JsonObject import org.json.JSONObject - @Serializable sealed class WalletResponse<T> { @Serializable @@ -96,11 +95,11 @@ data class WalletErrorInfo( class JSONObjectDeserializer : KSerializer<JSONObject> { - override val descriptor = PrimitiveDescriptor("JSONObjectDeserializer", STRING) + override val descriptor = PrimitiveSerialDescriptor("JSONObjectDeserializer", STRING) override fun deserialize(decoder: Decoder): JSONObject { - val input = decoder as JsonInput - val tree = input.decodeJson() as JsonObject + val input = decoder as JsonDecoder + val tree = input.decodeJsonElement() as JsonObject return JSONObject(tree.toString()) } diff --git a/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt b/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt index 3d00900..99a6ec8 100644 --- a/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt @@ -58,7 +58,7 @@ class PromptPaymentFragment : Fragment(), ProductImageClickListener { } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - paymentManager.payStatus.observe(viewLifecycleOwner, this::onPaymentStatusChanged) + paymentManager.payStatus.observe(viewLifecycleOwner, ::onPaymentStatusChanged) paymentManager.detailsShown.observe(viewLifecycleOwner, Observer { shown -> beginDelayedTransition(view as ViewGroup) val res = if (shown) R.string.payment_hide_details else R.string.payment_show_details @@ -91,7 +91,7 @@ class PromptPaymentFragment : Fragment(), ProductImageClickListener { } } - private fun onPaymentStatusChanged(payStatus: PayStatus) { + private fun onPaymentStatusChanged(payStatus: PayStatus?) { when (payStatus) { is PayStatus.Prepared -> { showLoading(false) |