-
Notifications
You must be signed in to change notification settings - Fork 635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate declarations with internal/package-private visibility #2534
Comments
might be related to https://youtrack.jetbrains.com/issue/KT-64124 |
All changes you've described here are, in fact, connected with your original request and made to make generated declarations less intrusive for tools.
For the rest of the declarations: it is by design that they are |
That's nice to hear, probably should have dug a bit deeper before opening this issue.
For this class I understand that the package org.example
@Serializable
public class Data(public val data: String)
But why is the generated serializer also public? It can be obtained with
If you write a custom serializer, it doesn't have to be public: @OptIn(ExperimentalSerializationApi::class)
@Serializer(forClass = Data::class) // or some other way to write a custom serializer
private object DataSerializer
@Serializable(with = DataSerializer::class)
public class Data(public val data: String) |
Yes and no. Some older versions of the plugin reference serializer directly instead of using
Because |
I see, so this seems like this can't be changed in the short term.
It's technically package-private, as can be seen by Thanks! |
What is your use-case and why do you need this feature?
Some classes and methods generated by the compiler plugin seem to have public JVM visibility, as can be seen with a tool like Binary compatibility validator.
This can lead to huge changes in files tracking public api in libraries using kotlinx.serialization when the generation logic changes. An example for this are a couple commits in the Kord library:
public static final synthetic field descriptor Lkotlinx/serialization/descriptors/SerialDescriptor;
disappeared in generated serializer classes with Kotlin 1.8.0write$Self
methods in serializable classes becamesynthetic
with Kotlin 1.8.20synthetic
constructors takingkotlinx.serialization.internal.SerializationConstructorMarker
andwrite$Self
methods disappeared in serializable classes with Kotlin 1.9.20(fixed by KT-64124), generated serializer classes changed fromsynthetic
constructors andwrite$Self
methods are backfinal
tosynthetic
and some methods in generated serializer classes are nowfinal
with K2Describe the solution you'd like
To avoid changes in the generation logic of the serialization compiler plugin causing changes in the public api of libraries using it, generated declarations should have lower visibility than
public
, e.g.internal
(or even package-private to avoid exposing them to Java clients). These lower visibilities are usually ignored by tools like BCV.The text was updated successfully, but these errors were encountered: