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,38 +1,49 @@
|
|||||||
package com.github.insanusmokrassar.SauceNaoAPI.models
|
package com.github.insanusmokrassar.SauceNaoAPI.models
|
||||||
|
|
||||||
import kotlinx.serialization.Optional
|
import com.github.insanusmokrassar.SauceNaoAPI.utils.CommonMultivariantStringSerializer
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.internal.ArrayListSerializer
|
||||||
|
import kotlinx.serialization.internal.StringSerializer
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class ResultData(
|
data class ResultData(
|
||||||
|
@Serializable(CommonMultivariantStringSerializer::class)
|
||||||
@SerialName("danbooru_id")
|
@SerialName("danbooru_id")
|
||||||
@Optional
|
@Optional
|
||||||
val danbooruId: String? = null,
|
val danbooruId: String? = null,
|
||||||
|
@Serializable(CommonMultivariantStringSerializer::class)
|
||||||
@SerialName("gelbooru_id")
|
@SerialName("gelbooru_id")
|
||||||
@Optional
|
@Optional
|
||||||
val gelbooruId: String? = null,
|
val gelbooruId: String? = null,
|
||||||
|
@Serializable(CommonMultivariantStringSerializer::class)
|
||||||
@SerialName("drawr_id")
|
@SerialName("drawr_id")
|
||||||
@Optional
|
@Optional
|
||||||
val drawrId: String? = null,
|
val drawrId: String? = null,
|
||||||
|
@Serializable(CommonMultivariantStringSerializer::class)
|
||||||
@SerialName("pixiv_id")
|
@SerialName("pixiv_id")
|
||||||
@Optional
|
@Optional
|
||||||
val pixivId: String? = null,
|
val pixivId: String? = null,
|
||||||
|
@Serializable(CommonMultivariantStringSerializer::class)
|
||||||
@Optional
|
@Optional
|
||||||
val title: String? = null,
|
val title: String? = null,
|
||||||
|
@Serializable(CommonMultivariantStringSerializer::class)
|
||||||
@Optional
|
@Optional
|
||||||
val creator: String? = null,
|
val creator: String? = null,
|
||||||
|
@Serializable(CommonMultivariantStringSerializer::class)
|
||||||
@Optional
|
@Optional
|
||||||
val material: String? = null,
|
val material: String? = null,
|
||||||
|
@Serializable(CommonMultivariantStringSerializer::class)
|
||||||
@SerialName("member_name")
|
@SerialName("member_name")
|
||||||
@Optional
|
@Optional
|
||||||
val memberName: String? = null,
|
val memberName: String? = null,
|
||||||
|
@Serializable(CommonMultivariantStringSerializer::class)
|
||||||
@SerialName("member_id")
|
@SerialName("member_id")
|
||||||
@Optional
|
@Optional
|
||||||
val memberId: String? = null,
|
val memberId: String? = null,
|
||||||
|
@Serializable(CommonMultivariantStringSerializer::class)
|
||||||
@Optional
|
@Optional
|
||||||
val characters: String? = null,
|
val characters: String? = null,
|
||||||
@SerialName("ext_urls")
|
@SerialName("ext_urls")
|
||||||
@Optional
|
@Optional
|
||||||
val extUrls: List<String> = emptyList()
|
val extUrls: List<String> = emptyList()
|
||||||
)
|
)
|
||||||
|
@ -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