-
Notifications
You must be signed in to change notification settings - Fork 622
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
Any way to make the serializers not part of public API #2108
Comments
Given that your classes are public, it makes sense if their serializers are also public. By declaring a public class as serializable, you agree that anyone can use it in their own If your concern is binary compatibility for serializers, we are well aware of this situation and do not make changes to it until it is absolutely necessary, so you can be sure that |
Thanks a lot for the clarification, that makes sense. |
Any chance this could be supported in the future? The use case is to hide the serialization format from callers. For an example, an initial version of a lib could use Json for readability/convenience but then switch to protobuf for performance later down the road. By making the serialization format public, these kind of use cases are a lot harder to address. |
Another use case is to make |
One thing to keep in mind is the fact that the format is not actually part of the serializer at all. You use the same serializer for protobuf, json and other formats. Formats may have additional annotations that are interpreted in a format specific way. Those annotations are also public (and part of the serialdescriptor), but shouldn't really be interpreted outside the format. |
@pdvrieze is absolutely right. The format is not a part of a public API; generated serializer does not depend on it. You may even provide a library with serializable classes without dependency on any actual format — using kotlinx-serialization-core artifact instead of json. Regarding implementation dependency — I may be wrong, but you would need it any way to read |
TIL, thanks! I think the argument still holds for the serialization mecanism. If I switch to protobuf, maybe I want to use wire or something else. Putting the serializer in the API exposes unnecessary implementation details.
The consuming project doesn't need to access @Serializable
class SomePublicClass {
val prop1: String
val prop2: String
// ... more props
fun serialize(source: BufferedSource) {
// implementation detail
}
} I understand this is not top priority but I think there are legit reasons to hide the implementation details while still keeping the class public. |
To be more precise here, the app consuming project has |
We've started to use kotlinx.serialization on some of our public classes, and that makes them expose new fields/methods/classes for the serializers, quite understandably. See this PR for instance, which shows the API diff via binary-compatibility-validator.
We were wondering if there could be any way to make those generated in a less public way (internal maybe?).
This is probably a long shot but we figured we should at least ask!
The text was updated successfully, but these errors were encountered: