micronaut-kotlin icon indicating copy to clipboard operation
micronaut-kotlin copied to clipboard

Add support for Kotlin serialization

Open raderio opened this issue 5 years ago • 6 comments

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.

raderio avatar Apr 14 '19 20:04 raderio

@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.

willbuck avatar Jan 06 '20 21:01 willbuck

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

graemerocher avatar Jan 08 '20 11:01 graemerocher

@raderio Any follow-up on this request?

willbuck avatar Apr 02 '20 14:04 willbuck

@raderio Any follow-up on this request?

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

  • https://github.com/spring-projects/spring-framework/issues/21188
  • https://github.com/spring-projects/spring-framework/blob/3e4ce9a348902d5b6379b37fb9dc6f9dc213f610/spring-web/src/main/java/org/springframework/http/converter/json/KotlinSerializationJsonHttpMessageConverter.java

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

NorbertSandor avatar Oct 05 '20 06:10 NorbertSandor

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

dave08 avatar Aug 20 '23 10:08 dave08

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.

fzoli avatar Aug 17 '24 12:08 fzoli