micronaut-projects / micronaut-kotlin

Additional projects that improve the Micronaut experience with Kotlin
Apache License 2.0
89 stars 17 forks source link

Add support for Kotlin serialization #47

Open raderio opened 5 years ago

raderio commented 5 years ago

https://github.com/Kotlin/kotlinx.serialization

Kotlin cross-platform / multi-format reflectionless serialization. Kotlin serialization consists of a compiler plugin, which automatically produces visitor code for classes, and runtime library, which uses generated code to serialize objects without reflection.

willbuck commented 4 years ago

@raderio is there something that would prevent you from using this? I haven't looked into it that closely yet, but I'm not certain we would be able to easily accommodate this in the internals of micronaut-core, as we want to support Java and Groovy as well, so Jackson's interoperability on all the JVM languages makes the most sense to use.

Can you provide more detail as to what "supporting" kotlin serialization would look like? Nothing should prevent you from using this yourself in your application code that I'm aware of.

graemerocher commented 4 years ago

If a module were to be built or contributed think it makes more sense here

willbuck commented 4 years ago

@raderio Any follow-up on this request?

NorbertSandor commented 4 years ago

@raderio Any follow-up on this request?

Only as info, Spring will support kotlinx.serialization as an alternative to Jackson:

I think that many Kotlin users would be happy with a similar solution in Micronaut as well ;)

dave08 commented 1 year ago

An extra plus for this implementation would be support for kotlin's value classes which I think Jackson can't support...

fzoli commented 3 months ago

An extra plus for this implementation would be support for kotlin's value classes which I think Jackson can't support...

Oh yes! This is my primary reason for preferring kotlinx serialization over any other library. Moreover, it is a bit faster thanks to build-time source code generation (which is also preferred by Micronaut).

I really hate when there are two UUIDs in a function argument, and someone calls it with the wrong order, and it still compiles. A UserId is not an AccountId. Yes, both are represented by UUIDs, but who cares?

I have just started learning Micronaut. I plan to migrate from Spring Boot and use the native runtime. (In theory, Spring supports native builds too, but at the end of the day, it just doesn't work... There's always some forgotten reflection somewhere... So, I have to run tests on the JVM, collect reflection/proxy data, recompile it with the collected info, and then test it again... lol. No way. Who has time to wait for that?)

In Spring Boot, there is a springdoc library that generates the OpenAPI YAML, but it only supports FasterXML Jackson. Yes, I can switch to kotlinx serialization, but then the generated OpenAPI will be inconsistent. This is an open issue in springdoc. I think it could be problematic here too.