mirror of
https://github.com/InsanusMokrassar/SauceNaoAPI.git
synced 2024-12-23 05:07:12 +00:00
add CommonMultivariantStringSerializer
This commit is contained in:
parent
6dd9638059
commit
90cb96a08a
@ -1,35 +1,46 @@
|
||||
package com.github.insanusmokrassar.SauceNaoAPI.models
|
||||
|
||||
import kotlinx.serialization.Optional
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import com.github.insanusmokrassar.SauceNaoAPI.utils.CommonMultivariantStringSerializer
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.ArrayListSerializer
|
||||
import kotlinx.serialization.internal.StringSerializer
|
||||
|
||||
@Serializable
|
||||
data class ResultData(
|
||||
@Serializable(CommonMultivariantStringSerializer::class)
|
||||
@SerialName("danbooru_id")
|
||||
@Optional
|
||||
val danbooruId: String? = null,
|
||||
@Serializable(CommonMultivariantStringSerializer::class)
|
||||
@SerialName("gelbooru_id")
|
||||
@Optional
|
||||
val gelbooruId: String? = null,
|
||||
@Serializable(CommonMultivariantStringSerializer::class)
|
||||
@SerialName("drawr_id")
|
||||
@Optional
|
||||
val drawrId: String? = null,
|
||||
@Serializable(CommonMultivariantStringSerializer::class)
|
||||
@SerialName("pixiv_id")
|
||||
@Optional
|
||||
val pixivId: String? = null,
|
||||
@Serializable(CommonMultivariantStringSerializer::class)
|
||||
@Optional
|
||||
val title: String? = null,
|
||||
@Serializable(CommonMultivariantStringSerializer::class)
|
||||
@Optional
|
||||
val creator: String? = null,
|
||||
@Serializable(CommonMultivariantStringSerializer::class)
|
||||
@Optional
|
||||
val material: String? = null,
|
||||
@Serializable(CommonMultivariantStringSerializer::class)
|
||||
@SerialName("member_name")
|
||||
@Optional
|
||||
val memberName: String? = null,
|
||||
@Serializable(CommonMultivariantStringSerializer::class)
|
||||
@SerialName("member_id")
|
||||
@Optional
|
||||
val memberId: String? = null,
|
||||
@Serializable(CommonMultivariantStringSerializer::class)
|
||||
@Optional
|
||||
val characters: String? = null,
|
||||
@SerialName("ext_urls")
|
||||
|
@ -0,0 +1,19 @@
|
||||
package com.github.insanusmokrassar.SauceNaoAPI.utils
|
||||
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.ArrayListSerializer
|
||||
import kotlinx.serialization.internal.StringSerializer
|
||||
|
||||
|
||||
@Serializer(String::class)
|
||||
object CommonMultivariantStringSerializer : KSerializer<String> by StringSerializer {
|
||||
private val stringArraySerializer = ArrayListSerializer(StringSerializer)
|
||||
|
||||
override fun deserialize(decoder: Decoder): String {
|
||||
return try {
|
||||
decoder.decodeSerializableValue(StringSerializer)
|
||||
} catch (e: Exception) {
|
||||
decoder.decodeSerializableValue(stringArraySerializer).joinToString()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user