diff --git a/plugins/kotlinx-serialization/kotlinx-serialization.backend/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/IrSerializableProperties.kt b/plugins/kotlinx-serialization/kotlinx-serialization.backend/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/IrSerializableProperties.kt index 7f954f05c59bd..d5abb7f5c7f06 100644 --- a/plugins/kotlinx-serialization/kotlinx-serialization.backend/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/IrSerializableProperties.kt +++ b/plugins/kotlinx-serialization/kotlinx-serialization.backend/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/IrSerializableProperties.kt @@ -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() diff --git a/plugins/kotlinx-serialization/testData/boxIr/externalSerialierJava.kt b/plugins/kotlinx-serialization/testData/boxIr/externalSerialierJava.kt new file mode 100644 index 0000000000000..e3e735616dde1 --- /dev/null +++ b/plugins/kotlinx-serialization/testData/boxIr/externalSerialierJava.kt @@ -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 { + 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" +} \ No newline at end of file diff --git a/plugins/kotlinx-serialization/tests-gen/org/jetbrains/kotlinx/serialization/runners/SerializationFirBlackBoxTestGenerated.java b/plugins/kotlinx-serialization/tests-gen/org/jetbrains/kotlinx/serialization/runners/SerializationFirBlackBoxTestGenerated.java index ee3931dfe72a7..0eb5e4d47f84a 100644 --- a/plugins/kotlinx-serialization/tests-gen/org/jetbrains/kotlinx/serialization/runners/SerializationFirBlackBoxTestGenerated.java +++ b/plugins/kotlinx-serialization/tests-gen/org/jetbrains/kotlinx/serialization/runners/SerializationFirBlackBoxTestGenerated.java @@ -57,6 +57,12 @@ public void testEnumsAreCached() throws Exception { 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 { diff --git a/plugins/kotlinx-serialization/tests-gen/org/jetbrains/kotlinx/serialization/runners/SerializationIrBoxTestGenerated.java b/plugins/kotlinx-serialization/tests-gen/org/jetbrains/kotlinx/serialization/runners/SerializationIrBoxTestGenerated.java index 6a5017ae8da5b..50a26920d250a 100644 --- a/plugins/kotlinx-serialization/tests-gen/org/jetbrains/kotlinx/serialization/runners/SerializationIrBoxTestGenerated.java +++ b/plugins/kotlinx-serialization/tests-gen/org/jetbrains/kotlinx/serialization/runners/SerializationIrBoxTestGenerated.java @@ -55,6 +55,12 @@ public void testEnumsAreCached() throws Exception { 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 {