Description
What is your use-case and why do you need this feature?
Reference to AxonFramework/extension-kotlin#124 (comment)
For Axon Framework I am investigating whether adding Kotlin Serialization is possible as a framework serializer.
The framework is developed with Java, and Kotlin is not a first-class language. However, the framework is very extensible and adding custom serialization implementations is straightforward.
During the investigation I was asked how the @Serializable
annotation and the auto-generated Serializer static/companion methods could be added to the existing classes that need serialization support.
I tried (see the linked comment above):
- Add a comple-only Kotlin serialization dependency
- Add the Kotlin serialization plugin
- Compile the code
I saw:
- The annotation is added as usual
- No auto-generated
serializer()
static/companion method is generated. - The Kotlin runtime JSON serializer dependency cannot serialize the class.
This makes adding Kotlin serialization to existing Java projects without Kotlin dependencies hard/impossible.
Describe the solution you'd like
For a (non-Kotlin) Java project, it should be possible to add the @Serializable
annotation to the Java source code with a compile-only dependency, and let the Gradle/Maven compiler plugin generate the serializer()
static/companion methods.
Another (separate) project (with Kotlin as a depedency) can then implement a custom serialization implementation, which can serialize all the annotated @Serializable
classes automatically.