arrow-kt / arrow-meta-examples

Some examples for Λrrow Meta the functional companion to Kotlin's Compiler & IDE.
Apache License 2.0
58 stars 20 forks source link

Added inline-serialization example #23

Open mel4tonin4 opened 4 years ago

mel4tonin4 commented 4 years ago

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 commented 4 years ago

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