Is there any alternative for JSON serialization in...
# multiplatform
p
Is there any alternative for JSON serialization in KMP, I am currently using kotlinx serialization?
🧵 1
👀 1
m
Not really. What's wrong with kotlinx.serialization?
👆 1
m
the point of kotlin multiplatform is to use the platform APIs if needed. Why not just do that?
1
p
@mbonnin I am using my KMP library in my Java backend project. In which I have some serialization code. Now while calling the serializer from my Java end I am getting this issue,
Exception in thread "main" java.lang.NoClassDefFoundError: kotlinx/serialization/json/Json
at codes.pratik.kmmlibrary.form.FormLogic.setRules(FormLogic.kt:400)
at form.FormListener.initiate(FormListener.java:19)
at App.main(App.java:12)
Caused by: java.lang.ClassNotFoundException: kotlinx.serialization.json.Json
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
... 3 more
I have asked this same question before on community but didn't get any answers, so I am searching for an alternative.
m
Looks like a classloading issue. If you can share a reproducer this should be fixable
Double check your runtime classpath
p
Sure, I will make a miniature version of my use case.
@mbonnin I created the sample project demonstrating my issue with serialization. here is the link to the project, https://github.com/pratik-kate/KMMLibrary
m
How do I reproduce the issue?
p
You can build the .jar file using
gradle jvmjar
and use that jar file in any sample Java project. If you want I can share that Java project too.
Here is the Java project with .jar file integration generated from KMM library https://github.com/pratik-kate/KMM
m
This is the problem. The .jar alone is not enough, you need the dependencies. This is the same for all JSON parsers.
I recommend you publish to a maven repository and Gradle will pull dependencies for you
Or else you will need a fat jar https://www.baeldung.com/gradle-fat-jar
p
Thank you so much, I will try creating Fat Jar.
👍 1
165 Views