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..90c252689470e 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 @@ -1,5 +1,5 @@ /* - * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -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..d952b45dabc10 --- /dev/null +++ b/plugins/kotlinx-serialization/testData/boxIr/externalSerialierJava.kt @@ -0,0 +1,29 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// 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 ced8564e05832..bbeb6c5559c8d 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 @@ -45,6 +45,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("expectActual.kt") public void testExpectActual() 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 9a3b20343e884..e401e44971b7b 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 @@ -43,6 +43,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("expectActual.kt") public void testExpectActual() throws Exception {