[FIR] Try to load properties in order according to kotlinx.serialization metadata extension
Move metadata extension with property order from kotlinx.serialization to core After fix of KT-54792 properties will be deserialized in declaration order if corresponding class was compiled with modern compiler. But this order is needed for kotlinx.serialization for binaries compiled with any kotlin compiler >= 1.4. Since we don't plan to add any extension points into (de)serialization into FIR, we need to take into account existing metadata extension from kotlinx.serialization in compiler itself ^KT-57769 Fixed
This commit is contained in:
committed by
Space Team
parent
7685284cb7
commit
94f77add49
+11
-2
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.gradle.testbase.*
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
|
||||
@OtherGradlePluginTests
|
||||
class KotlinxSerializationMppK2IT : KGPBaseTest() {
|
||||
class K2KotlinxSerializationIT : KGPBaseTest() {
|
||||
private val gradleVersion = GradleVersion.version(TestVersions.Gradle.MAX_SUPPORTED)
|
||||
|
||||
@DisplayName("Compile common code to metadata with kotlinx.serialization and K2")
|
||||
@@ -19,7 +19,16 @@ class KotlinxSerializationMppK2IT : KGPBaseTest() {
|
||||
project("kotlinxSerializationMppK2", gradleVersion) {
|
||||
build(":compileCommonMainKotlinMetadata") {
|
||||
assertTasksExecuted(":compileCommonMainKotlinMetadata")
|
||||
assertOutputContains("BUILD SUCCESSFUL")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("Compile code with kotlinx.serialization with K2 against K1")
|
||||
@GradleTest
|
||||
fun `test kotlinx serialization K2 against K1`() {
|
||||
project("kotlinxSerializationK2AgainstK1", gradleVersion) {
|
||||
build(":app:run") {
|
||||
assertTasksExecuted(":app:run")
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
|
||||
|
||||
plugins {
|
||||
application
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":lib"))
|
||||
}
|
||||
|
||||
val compileKotlin: KotlinCompile by tasks
|
||||
|
||||
compileKotlin.compilerOptions {
|
||||
languageVersion.set(KotlinVersion.KOTLIN_2_0)
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass.set("foo.MainKt")
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package foo
|
||||
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
class Derived(val d: Long = 1000000000000) : Base(2, "world", listOf("b", "c")) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is Derived) return false
|
||||
return a == other.a && b == other.b && c == other.c && d == other.d
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "a: $a, b: $b, c: $c, d: $d"
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val expected = Derived(12)
|
||||
val result = Json.encodeToString(Derived.serializer(), expected)
|
||||
if (result != """{"c":2,"b":"world","a":["b","c"],"d":12}""") {
|
||||
throw IllegalStateException("Error: $result")
|
||||
}
|
||||
val actual = Json.decodeFromString(Derived.serializer(), result)
|
||||
if (expected != actual) {
|
||||
throw IllegalStateException("expected: $expected\nactual: $actual")
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
plugins {
|
||||
kotlin("jvm") apply false
|
||||
kotlin("plugin.serialization") apply false
|
||||
java
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
subprojects {
|
||||
apply {
|
||||
plugin("java")
|
||||
plugin("kotlin")
|
||||
plugin("org.jetbrains.kotlin.plugin.serialization")
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0")
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
|
||||
|
||||
val compileKotlin: KotlinCompile by tasks
|
||||
|
||||
compileKotlin.compilerOptions {
|
||||
languageVersion.set(KotlinVersion.KOTLIN_1_9)
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package foo
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
open class Base(
|
||||
val c: Int = 1,
|
||||
val b: String = "hello",
|
||||
val a: List<String> = listOf("a")
|
||||
)
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
rootProject.name = "kotlinxSerializationK2AgainstK1"
|
||||
|
||||
include(":lib", "app")
|
||||
Reference in New Issue
Block a user