Skip properties from Java classes for which the getter type is unknown
thus avoiding NPE when auto-generating external serializers. #KT-55681 Fixed
This commit is contained in:
committed by
Space Team
parent
a1894ed027
commit
0b4f534d35
+1
-1
@@ -74,7 +74,7 @@ internal fun serializablePropertiesForIrBackend(
|
||||
if (irClass.isInternalSerializable) !it.annotations.hasAnnotation(SerializationAnnotations.serialTransientFqName)
|
||||
else !DescriptorVisibilities.isPrivate(it.visibility) && ((it.isVar && !it.annotations.hasAnnotation(SerializationAnnotations.serialTransientFqName)) || primaryParamsAsProps.contains(
|
||||
it
|
||||
))
|
||||
)) && it.getter?.returnType != null // For some reason, some properties from Java (like java.net.URL.hostAddress) do not have getter. Let's ignore them, as they never have worked properly in K1 either.
|
||||
|
||||
val (primaryCtorSerializableProps, bodySerializableProps) = properties
|
||||
.asSequence()
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.descriptors.*
|
||||
import kotlinx.serialization.encoding.*
|
||||
import java.net.URL
|
||||
|
||||
|
||||
// @Serializer should do nothing if all methods are overriden
|
||||
@Serializer(forClass = URL::class)
|
||||
object URLSerializer : KSerializer<URL> {
|
||||
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("java.net.URL", PrimitiveKind.STRING)
|
||||
|
||||
override fun serialize(encoder: Encoder, value: URL) {
|
||||
TODO()
|
||||
}
|
||||
|
||||
override fun deserialize(decoder: Decoder): URL {
|
||||
TODO()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (URLSerializer.descriptor.toString() != "PrimitiveDescriptor(java.net.URL)") return URLSerializer.descriptor.toString()
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -57,6 +57,12 @@ public class SerializationFirBlackBoxTestGenerated extends AbstractSerialization
|
||||
runTest("plugins/kotlinx-serialization/testData/boxIr/enumsAreCached.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("externalSerialierJava.kt")
|
||||
public void testExternalSerialierJava() throws Exception {
|
||||
runTest("plugins/kotlinx-serialization/testData/boxIr/externalSerialierJava.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericBaseClassMultiple.kt")
|
||||
public void testGenericBaseClassMultiple() throws Exception {
|
||||
|
||||
+6
@@ -55,6 +55,12 @@ public class SerializationIrBoxTestGenerated extends AbstractSerializationIrBoxT
|
||||
runTest("plugins/kotlinx-serialization/testData/boxIr/enumsAreCached.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("externalSerialierJava.kt")
|
||||
public void testExternalSerialierJava() throws Exception {
|
||||
runTest("plugins/kotlinx-serialization/testData/boxIr/externalSerialierJava.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericBaseClassMultiple.kt")
|
||||
public void testGenericBaseClassMultiple() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user