iamthevoid
01/26/2022, 3:21 PMiamthevoid
01/26/2022, 3:22 PM@Serializable
data class Simple(val errorCode: ServerErrors)
iamthevoid
01/26/2022, 3:23 PM@Serializable
enum class ServerErrors {
@SerialName("TMP_PASS_ACCESS_FORBIDDEN")
TmpPassAccessForbidden,
...
}
iamthevoid
01/26/2022, 3:23 PM{
"errorCode": "CAPTCHA_REQUIRED",
"captchaId": "g378c6b58736c5u38d6u3huh",
"captchaUrl": "<https://miro.medium.com/max/2400/1*uq_w8ytWwx5GjmFzgTUwqw.gif>"
}
iamthevoid
01/26/2022, 3:24 PMCan not parse Simple from {
"errorCode" : "CAPTCHA_REQUIRED",
"captchaId": "g378c6b58736c5u38d6u3huh",
"captchaUrl": "<https://miro.medium.com/max/2400/1*uq_w8ytWwx5GjmFzgTUwqw.gif>"
}
kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 41: Encountered an unknown key 'captchaId'.
Use 'ignoreUnknownKeys = true' in 'Json {}' builder to ignore unknown keys.
JSON input: {
"errorCode" : "CAPTCHA_REQUIRED",
"captchaId": "g378c6b58736c5u38d6u3huh",
"captchaUrl": "<https://miro.medium.com/max/2400/1*uq_w8ytWwx5GjmFzgTUwqw.gif>"
}
iamthevoid
01/26/2022, 3:24 PM@OptIn(ExperimentalSerializationApi::class)
val client: HttpClient by lazy {
HttpConfig.httpClient(providedProxy = proxy) {
Json {
serializer = KotlinxSerializer(
kotlinx.serialization.json.Json {
encodeDefaults = true
ignoreUnknownKeys = true
useAlternativeNames = false
isLenient = true
explicitNulls = false
}
)
}
Nikky
01/26/2022, 3:25 PMJson {
encodeDefaults = true
ignoreUnknownKeys = true
useAlternativeNames = false
isLenient = true
explicitNulls = false
}
or such, or is that a different type ?iamthevoid
01/26/2022, 3:26 PMNikky
01/26/2022, 3:27 PMiamthevoid
01/26/2022, 3:29 PMNikky
01/26/2022, 3:29 PMNikky
01/26/2022, 3:30 PMNikky
01/26/2022, 3:32 PMval client = HttpClient(httpEngine) {
install(ContentNegotiation) {
json(
Json {
encodeDefaults = true
ignoreUnknownKeys = true
useAlternativeNames = false
isLenient = true
explicitNulls = false
}
)
}
}
not sure what that HttpConfig.httpClient()
call of yours is fromiamthevoid
01/26/2022, 3:36 PMiamthevoid
01/26/2022, 3:40 PMiamthevoid
01/26/2022, 3:40 PMNikky
01/26/2022, 3:42 PM@Deprecated("Please use ContentNegotiation plugin and its converters")at least that what my IDE got to say about that.. seems like the website and the deprecation notices are not in sync, old ktor version ?
iamthevoid
01/26/2022, 3:43 PM1.6.0
Nikky
01/26/2022, 3:45 PMiamthevoid
01/26/2022, 3:48 PMunknown keys
in json before (but it is possible)Nikky
01/26/2022, 3:49 PMString
and dealing with them by hand, see if it also breaks, then its the classes or json config
if not.. maybe something in ktor is improperly configured..
i barely used that JsonFeature
before 2.0.0 myself.. it just seemed too flakyiamthevoid
01/26/2022, 3:49 PMiamthevoid
01/26/2022, 3:53 PMiamthevoid
01/26/2022, 3:53 PMiamthevoid
01/26/2022, 3:54 PMiamthevoid
01/26/2022, 3:55 PMjson.tryFromJson<Simple>(content)?.let { simpleError ->
when (simpleError.errorCode) {
ServerErrors.IpTemporaryBlocked, ServerErrors.UserTemporaryBlocked ->
json.fromJson<TimeBlock>(content)
ServerErrors.CaptchaRequired -> json.fromJson<CaptchaRequired>(content)
ServerErrors.CodeTimeout -> json.fromJson<CodeTimeout>(content)
ServerErrors.InvalidOtp -> json.fromJson<InvalidOtp>(content)
else -> simpleError
}
} ?: Unknown(throwable)