Shan
05/14/2020, 5:59 AMJsonDecodingException
? What is strange is that it works in certain cases, but fails in others. When I get back this response:
{
"id": 1,
"status": 1,
"info": 0
}
It works fine and returns IN_PROGRESS
. When I get this response:
{
"id": 3,
"status": 3,
"info": 0
}
I encounter this error:
kotlinx.serialization.json.JsonDecodingException: Invalid JSON at 28: Expected string or non-null literal
Which is thrown from takeString()
in JsonReader.kt
after trying to call decodeInt()
. If both of them were failing I would be a little less confused, but with only one of them failing I am at a loss. Is it interpreting the 3
as a byte or something, and thus failing the TC_OTHER
and TC_STRING
check, whereas the 1
is interpreted as a TC_STRING
somehow? All I can think of 🤔turansky
05/14/2020, 3:15 PM@SerialId
for automatic serializationturansky
05/14/2020, 3:16 PMShan
05/14/2020, 5:09 PMturansky
05/14/2020, 6:06 PMturansky
05/14/2020, 6:08 PM"IN_PROGRESS"
-> <http://StatusCode.IN|StatusCode.IN>_PROGRESS
Shan
05/14/2020, 6:17 PMturansky
05/14/2020, 6:29 PM@Serializer(with=...)
on enumShan
05/14/2020, 7:07 PM@Serializable
enum class StatusCode {
@SerialId(1) IN_PROGRESS,
@SerialId(2) SHOULD_RETRY,
@SerialId(3) SHOULD_NOT_RETRY;
}
With this response:
{
"id": 1,
"status": 1,
"info": 0
}
Produces:
kotlinx.serialization.SerializationException: StatusCode does not contain element with name '1'
Shan
05/14/2020, 7:11 PMShan
05/14/2020, 7:22 PMShan
05/14/2020, 7:30 PMturansky
05/14/2020, 7:59 PMSerialId
doen’t work in your cases?Shan
05/14/2020, 8:26 PMStatusCode does not contain element with name '1'
. Not sure if I implemented it correctly or not, couldn't find solid information on how I was supposed to use it unfortunately, just a few scattered examples.turansky
05/14/2020, 10:24 PMNikky
05/15/2020, 6:35 PMvalues().first {
it.code == decoder.decodeInt()
}
}
seems like it takes a new int from the decoder for each comparison, so it might not have more data
it would make more sense to decode the value and then search in values()