https://kotlinlang.org logo
#http4k
Title
# http4k
p

Philipp Mayer

03/24/2021, 9:41 PM
What do you guys recommend as JSON library when one wants to build a native executable with GraalVM? I wanted to try out Moshi, but
Copy code
val socketLens = Body.auto<Set<Socket>>().toLens()
just throws
Copy code
No JsonAdapter for class java.util.LinkedHashSet, you should probably use Set instead of LinkedHashSet (Moshi only supports the collection interfaces by default) or else register a custom JsonAdapter.
and I'm not sure if I really want to add all of that: https://pulseadvancedmedia.co.uk/java/moshi-adapters-for-platform-types-like-arraylist-and-linkedlist/ Any tips what I'm missing? What are you guys using? I'm just used to Jackson, but it makes use of reflection, so I rather not use it for GraalVM I guess. Thanks in advance!
d

dave

03/24/2021, 9:50 PM
you're kind of a little bit stuck to be honest. Moshi is by far and away the best option if you can get away with it as it's much lighterweight than Jackson- you can investigate using something like Kotshi to generate the adapters (as we do in http4k-connect) - or maybe do something custom with KotlinPoet? There is also 'kondor-json' which is very (new and) functional, but it's probably not going to make your life easier in the regard of having to write code: https://github.com/uberto/kondor-json
p

Philipp Mayer

03/24/2021, 9:52 PM
Ah, I stumbled over kotshi when skimming through http4k-connect. Completely forgot that. Thanks!
d

dave

03/24/2021, 9:53 PM
np. we wrote a kustom (!) code generator in http4k-connect if you need an example of a kapt processor.
p

Philipp Mayer

03/24/2021, 9:54 PM
Well it's the only endpoint in that example, but I guess Moshi would be something that I would make use of in a bigger project. I will look intro Kotshi I guess.
Woah, that's quite an effort
btw, I just have to drop that I love the lens feature. I wasn't aware of it at all (typical spring user I guess..)
d

dave

03/24/2021, 9:56 PM
yes, it's quite satisfying that it works so neatly, although I do seem to wonder about how much time I spend writing code which marshalls things from one form to another! And I've just finished using it in connect as well (see next message) 😂
😂 1
r

Razvan

03/27/2021, 10:09 AM
Wasn’t Argo supposed to be helpful for GraalVM as it does not use reflexion ? But as it does not support auto-marshalling I guess is not that useful, unless you are doing the mapping manually
3 Views