Moshi 将值反序列化为 null
Moshi deserializing values as null
我最近从 Gson 切换到 Moshi,但在解析某些 Json 时遇到问题。
{
"access_token": "-LNe2LQ7DQH5Y2zs_W5iUumKuaUE",
"token_type": "bearer",
"device_id": "461f-837e-af5050c92fe9",
"expires_in": 3600,
"scope": "*"
}
这是模型 class:
data class AuthToken(
@Json(name = "access_token") val accessToken: String,
@Json(name = "token_type") val tokenType: String,
@Json(name = "device_id") val deviceId: String,
@Json(name = "expires_in") val expiresIn: Int,
@Json(name = "scope") val scope: String
)
每当我在改造客户端中切换到使用 Moshi 时,我都会收到以下错误:
java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull
我已将字段设为可为空,但它始终反序列化为空。我已经检查了我的改装响应,并且(显然)在使用 Gson 或 Moshi 时是一样的。我究竟做错了什么?
出于某种原因,当我明确告诉 AuthToken
class 生成适配器时 - 我没有收到空值。
@JsonClass(generateAdapter = true)
data class AuthToken(
@Json(name = "access_token") val accessToken: String,
@Json(name = "token_type") val tokenType: String,
@Json(name = "device_id") val deviceId: String,
@Json(name = "expires_in") val expiresIn: Int,
@Json(name = "scope") val scope: String
)
我最近从 Gson 切换到 Moshi,但在解析某些 Json 时遇到问题。
{
"access_token": "-LNe2LQ7DQH5Y2zs_W5iUumKuaUE",
"token_type": "bearer",
"device_id": "461f-837e-af5050c92fe9",
"expires_in": 3600,
"scope": "*"
}
这是模型 class:
data class AuthToken(
@Json(name = "access_token") val accessToken: String,
@Json(name = "token_type") val tokenType: String,
@Json(name = "device_id") val deviceId: String,
@Json(name = "expires_in") val expiresIn: Int,
@Json(name = "scope") val scope: String
)
每当我在改造客户端中切换到使用 Moshi 时,我都会收到以下错误:
java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull
我已将字段设为可为空,但它始终反序列化为空。我已经检查了我的改装响应,并且(显然)在使用 Gson 或 Moshi 时是一样的。我究竟做错了什么?
出于某种原因,当我明确告诉 AuthToken
class 生成适配器时 - 我没有收到空值。
@JsonClass(generateAdapter = true)
data class AuthToken(
@Json(name = "access_token") val accessToken: String,
@Json(name = "token_type") val tokenType: String,
@Json(name = "device_id") val deviceId: String,
@Json(name = "expires_in") val expiresIn: Int,
@Json(name = "scope") val scope: String
)