Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Added inline-serialization example #23

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mel4tonin4
Copy link

@mel4tonin4 mel4tonin4 commented May 5, 2020

This is a small compiler plug-in that generates a serializer for a given class with a single val argument in the primary constructor which will serialize the class inline. This is typically something that you may want with data classes of this kind:

data class TimeSec(val value : Double)

An instance of this class would be serialized to JSON as something like

{ "value": 4.5 }

Marking the class with @InlineSerializable will cause this compiler plug-in to generate a serializer that will serialize the same object as

4.5

The serializer is also associated with the class.

Note that, while data classes of this kind are obvious candidates for being inline classes, currently Kotlin does not support serialization of inline classes. In my case, this means that I have a plethora of data classes waiting to be converted to inline classes as soon as that limitation is removed.

Feel free to include this example in your repository, if you find any value in it.

This is my first pull request. I'm at your disposal, in case you need any changes.

@rachelcarmena
Copy link
Member

Thank you so much @mel4tonin4 🎉 Sorry for the delayed response. Please, could you update it with Kotlin 1.4.10? Thanks!!

Copy link
Member

@rachelcarmena rachelcarmena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mel4tonin4 !! Thanks again for your contribution 🙌

Here an updated list of missing changes to include this example:

  • Use of latest Kotlin 1.5.0-RC
  • Upgrade to Gradle 6.8.3 (required by Kotlin version)
  • Update repositories:
-        maven { url 'https://oss.jfrog.org/artifactory/oss-snapshot-local/' }
+        maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
  • Update the plugin:
-                classDeclaration({ isAnnotatedWith<InlineSerializable>() } ) { c ->
+                classDeclaration(this, { isAnnotatedWith<InlineSerializable>() } ) { c ->
  • Replace the use of deprecated withName
  • Update kotlin.serialization dependency version.

Please, let us know if we can help you!

Thanks!!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants