fix strict json parsing
This commit is contained in:
parent
04bc439880
commit
a0b0e3d24d
|
@ -29,13 +29,17 @@ data class ApiMessage(
|
|||
) {
|
||||
|
||||
fun encode(): String {
|
||||
return JSON.stringify(Companion, this)
|
||||
return JSON.nonstrict.stringify(ApiMessage.serializer(), this)
|
||||
}
|
||||
|
||||
|
||||
override fun toString(): String = encode()
|
||||
|
||||
@Serializer(forClass = ApiMessage::class)
|
||||
companion object {
|
||||
val USER_ACTION = "user_action"
|
||||
val JOIN_LEAVE = "join_leave"
|
||||
|
||||
override fun serialize(output: Encoder, obj: ApiMessage) {
|
||||
val elemOutput = output.beginStructure(descriptor)
|
||||
obj.username.takeIf { it.isNotEmpty() }?.let {
|
||||
|
@ -77,12 +81,8 @@ data class ApiMessage(
|
|||
elemOutput.endStructure(descriptor)
|
||||
}
|
||||
|
||||
val USER_ACTION = "user_action"
|
||||
val JOIN_LEAVE = "join_leave"
|
||||
|
||||
|
||||
fun decode(json: String): ApiMessage {
|
||||
return JSON.nonstrict.parse(Companion, json)
|
||||
fun decode(input: String): ApiMessage {
|
||||
return JSON.nonstrict.parse(ApiMessage.serializer(), input)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ open class MessageHandler : CoroutineScope {
|
|||
|
||||
when (result) {
|
||||
is Result.Success -> {
|
||||
val messages: List<ApiMessage> = JSON.parse(ApiMessage.list, result.value)
|
||||
val messages: List<ApiMessage> = JSON.nonstrict.parse(ApiMessage.list, result.value)
|
||||
messages.forEach { msg ->
|
||||
logger.trace("skipping $msg")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue