Add Kotlin Serialization JSON compatibility
See original GitHub issueThe kotlinx.serialization
module for JSON doesn’t have easy support or tutorials in Javalin docs.
If you could, please add it for integration with this library.
Issue Analytics
- State:
- Created 3 years ago
- Comments:20 (11 by maintainers)
Top Results From Across the Web
Serialization | Kotlin
kotlinx.serialization provides sets of libraries for all supported platforms – JVM, JavaScript, Native – and for various serialization formats – ...
Read more >Add Kotlin Serialization JSON compatibility #1080 - GitHub
The kotlinx.serialization module for JSON doesn't have easy support or tutorials in Javalin docs. If you could, please add it for integration ...
Read more >Using the Kotlin Serialization Library for Tough JSON ...
We use the Kotlin serialization library, because it's compatible with Kotlin, has a faster runtime than Gson or Moshi, and can run on...
Read more >kotlinx.serialization 1.2 Released: High-Speed JSON ...
JSON serialization is faster than ever before. Version 1.2 is up to twice as fast as ... Kotlin 1.5 type system additions are...
Read more >Understanding Kotlin data serialization - LogRocket Blog
Kotlin uses a process called data serialization to convert data into other compatible data formats. This process is important because it ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sorry @Freezystem, I completely missed your reply!
You can read a bit about extension functions here: https://kotlinlang.org/docs/reference/extensions.html. You would have to do something like:
With your desired signatures.
Then you can import these when you want to use it, and call them like
ctx.kotlinxJson()
.In terms of writing a generic object to JSON with Gson or Jackson we see that they have options for using
Class<?>
and an additional option for usingjava.lang.reflect.Type
(Gson) or for Jackson it’s ownJavaType
orTypeReference<?>
.Gson:
https://www.javadoc.io/static/com.google.code.gson/gson/2.8.6/com.google.gson/com/google/gson/Gson.html#toJson(java.lang.Object,java.lang.reflect.Type)
Jackson:
http://fasterxml.github.io/jackson-databind/javadoc/2.10/com/fasterxml/jackson/databind/ObjectMapper.html#writerFor-java.lang.Class-
Conceptually in Java land for Gson it would suggest having an additional/overloaded toJson() that took
java.lang.reflect.Type
- but that wouldn’t work for Jackson which has it’s own JavaType and TypeReference (but for myself I don’t think we need this for Jackson and it would be worth checking Gson - as in, is this more a kotlin/kotlinx.serialization issue/requirement? I should confirm when Jackson and Gson need generic type on serialisation to json).Hmmm.