-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KxSerialization] Fixed access private custom serializer on property
When a custom serializer is specified on a type and this type is used in a property of another serializable class, then on the JVM this leads to an error accessing the custom serializer class - because it is private and located in another package. Fixes Kotlin/kotlinx.serialization#2495
- Loading branch information
Showing
5 changed files
with
86 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
plugins/kotlinx-serialization/testData/boxIr/privateCustomSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// TARGET_BACKEND: JVM_IR | ||
|
||
// WITH_STDLIB | ||
|
||
// FILE: serializer.kt | ||
|
||
package a | ||
|
||
import kotlinx.serialization.* | ||
import kotlinx.serialization.encoding.* | ||
import kotlinx.serialization.descriptors.* | ||
import kotlinx.serialization.json.* | ||
import kotlin.reflect.KClass | ||
import kotlin.test.* | ||
|
||
@Serializable(DataSerializer::class) | ||
data class Data( | ||
val i: Int | ||
) | ||
|
||
|
||
|
||
@Serializer(forClass = Data::class) | ||
private object DataSerializer | ||
|
||
// FILE: holder.kt | ||
|
||
package b | ||
|
||
import kotlinx.serialization.* | ||
import kotlinx.serialization.encoding.* | ||
import kotlinx.serialization.descriptors.* | ||
import kotlinx.serialization.json.* | ||
import kotlin.reflect.KClass | ||
import kotlin.test.* | ||
import a.Data | ||
|
||
@Serializable | ||
data class Holder( | ||
val data: Data | ||
) | ||
|
||
|
||
fun box(): String { | ||
val json = Json.encodeToString(Holder(Data(1))) | ||
return if (json == "{\"data\":{\"i\":1}}") "OK" else json | ||
} |
6 changes: 6 additions & 0 deletions
6
...tbrains/kotlinx/serialization/runners/SerializationFirLightTreeBlackBoxTestGenerated.java
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
...ests-gen/org/jetbrains/kotlinx/serialization/runners/SerializationIrBoxTestGenerated.java
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.