Skip to content

Commit

Permalink
Update ListLikeSerializer to CollectionLikeSerializer
Browse files Browse the repository at this point in the history
  • Loading branch information
F0Xde committed Jun 10, 2022
1 parent 8485484 commit 3c64beb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/BuildConstants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ object BuildConstants {
const val fabricApiVersion = "0.55.3+1.19"
const val fabricLanguageKotlinVersion = "1.8.0+kotlin.1.7.0"

// TODO: update to 5.4 when released for compatiblity with Kotlin 1.7
const val kotestVersion = "5.3.0"
const val mockkVersion = "1.12.4"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ internal val byteSerializer = serializer<Byte>()
internal val intSerializer = serializer<Int>()
internal val longSerializer = serializer<Long>()

private val listLikeSerializerClass = Class.forName("kotlinx.serialization.internal.ListLikeSerializer").kotlin
private val collectionLikeSerializerClass = Class.forName("kotlinx.serialization.internal.CollectionLikeSerializer").kotlin

@Suppress("unchecked_cast")
private val listLikeElementSerializerField = listLikeSerializerClass.declaredMemberProperties
private val collectionLikeElementSerializerField = collectionLikeSerializerClass.declaredMemberProperties
.first { it.name == "elementSerializer" }
.apply { isAccessible = true } as KProperty1<Any, KSerializer<*>>

internal val Any.elementSerializer: KSerializer<*>?
get() = if (listLikeSerializerClass.isInstance(this)) {
listLikeElementSerializerField.get(this)
get() = if (collectionLikeSerializerClass.isInstance(this)) {
collectionLikeElementSerializerField.get(this)
} else {
null
}

0 comments on commit 3c64beb

Please sign in to comment.