Skip to content

Commit

Permalink
AND-9338 Fix some classes serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
nzeeei authored and kozarezvlad committed Dec 6, 2024
1 parent 348f7ca commit 3ce1984
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.tangem.common

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import com.tangem.operations.CommandResponse

@JsonClass(generateAdapter = true)
data class SuccessResponse(val cardId: String) : CommandResponse
data class SuccessResponse(
@Json(name = "cardId")
val cardId: String,
) : CommandResponse
7 changes: 7 additions & 0 deletions tangem-sdk-core/src/main/java/com/tangem/common/UserCode.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.tangem.common

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import com.tangem.common.core.SessionEnvironment
import com.tangem.common.extensions.calculateSha256

@JsonClass(generateAdapter = true)
class UserCode constructor(
@Json(name = "type")
val type: UserCodeType,
@Json(name = "value")
val value: ByteArray?,
) {
constructor(type: UserCodeType) : this(type, type.defaultValue)
Expand All @@ -19,8 +22,12 @@ class UserCode constructor(
}
}

@JsonClass(generateAdapter = false)
enum class UserCodeType(val defaultValue: String) {
@Json(name = "AccessCode")
AccessCode(UserCode.DefaultAccessCode),

@Json(name = "Passcode")
Passcode(UserCode.DefaultPasscode),
;

Expand Down
16 changes: 15 additions & 1 deletion tangem-sdk-core/src/main/java/com/tangem/common/json/JSONRPC.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tangem.common.json

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import com.tangem.common.core.TangemError

Expand Down Expand Up @@ -55,18 +56,31 @@ class JSONRPCRequest constructor(

@JsonClass(generateAdapter = true)
data class JSONRPCResponse(
@Json(name = "result")
val result: Any?,
@Json(name = "error")
val error: JSONRPCError?,
@Json(name = "id")
val id: Int? = null,
@Json(name = "jsonrpc")
val jsonrpc: String = "2.0",
) : JSONStringConvertible

data class ErrorData(val code: Int, val message: String)
@JsonClass(generateAdapter = true)
data class ErrorData(
@Json(name = "code")
val code: Int,
@Json(name = "message")
val message: String,
)

@JsonClass(generateAdapter = true)
class JSONRPCError constructor(
@Json(name = "code")
val code: Int,
@Json(name = "message")
val message: String,
@Json(name = "data")
val data: ErrorData? = null,
) : JSONStringConvertible {

Expand Down

0 comments on commit 3ce1984

Please sign in to comment.