Use .fullyExpandedType to get serializable annotation from inside typealias
to correctly handle 'global customization via typealias' feature in K2 serialization plugin.
This commit is contained in:
committed by
Space Team
parent
76fc7ce0ad
commit
9586bf74e0
+2
-1
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.declarations.hasAnnotation
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isEnumClass
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.extensions.FirExtensionSessionComponent
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
@@ -77,7 +78,7 @@ val FirSession.contextualSerializersProvider: ContextualSerializersProvider by F
|
||||
context(CheckerContext)
|
||||
fun findTypeSerializerOrContextUnchecked(type: ConeKotlinType): FirClassSymbol<*>? {
|
||||
if (type.isTypeParameter) return null
|
||||
val annotations = type.customAnnotations
|
||||
val annotations = type.fullyExpandedType(session).customAnnotations
|
||||
annotations.serializableWith?.let { return it.toRegularClassSymbol(session) }
|
||||
val classSymbol = type.toRegularClassSymbol(session) ?: return null
|
||||
val currentFile = currentFile
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.json.*
|
||||
import kotlinx.serialization.descriptors.*
|
||||
import kotlinx.serialization.encoding.*
|
||||
import java.util.Date
|
||||
|
||||
class NotSerializable(val i: Int)
|
||||
|
||||
object SerializerB : KSerializer<NotSerializable> {
|
||||
override val descriptor: SerialDescriptor
|
||||
get() = PrimitiveSerialDescriptor("SerializerB", PrimitiveKind.STRING)
|
||||
|
||||
override fun serialize(encoder: Encoder, value: NotSerializable) = TODO()
|
||||
|
||||
override fun deserialize(decoder: Decoder): NotSerializable = TODO()
|
||||
}
|
||||
|
||||
object DateSer : KSerializer<Date> {
|
||||
override val descriptor = PrimitiveSerialDescriptor("DateSer", PrimitiveKind.DOUBLE)
|
||||
|
||||
override fun deserialize(decoder: Decoder): Date = TODO()
|
||||
|
||||
override fun serialize(encoder: Encoder, value: Date) = TODO()
|
||||
}
|
||||
|
||||
typealias S = @Serializable(SerializerB::class) NotSerializable
|
||||
typealias BS = @Serializable(DateSer::class) Date
|
||||
|
||||
@Serializable
|
||||
class Foo(
|
||||
val s: S,
|
||||
val bs: BS,
|
||||
val list: List<BS>
|
||||
)
|
||||
|
||||
fun box(): String {
|
||||
val list = Foo.serializer().descriptor.elementDescriptors.map { it.serialName }.toList()
|
||||
if (list != listOf("SerializerB", "DateSer", "kotlin.collections.ArrayList")) return list.toString()
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -128,6 +128,12 @@ public class SerializationFirBlackBoxTestGenerated extends AbstractSerialization
|
||||
public void testStarProjections() throws Exception {
|
||||
runTest("plugins/kotlinx-serialization/testData/boxIr/starProjections.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typealiasesTest.kt")
|
||||
public void testTypealiasesTest() throws Exception {
|
||||
runTest("plugins/kotlinx-serialization/testData/boxIr/typealiasesTest.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+6
@@ -126,4 +126,10 @@ public class SerializationIrBoxTestGenerated extends AbstractSerializationIrBoxT
|
||||
public void testStarProjections() throws Exception {
|
||||
runTest("plugins/kotlinx-serialization/testData/boxIr/starProjections.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typealiasesTest.kt")
|
||||
public void testTypealiasesTest() throws Exception {
|
||||
runTest("plugins/kotlinx-serialization/testData/boxIr/typealiasesTest.kt");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user