https://kotlinlang.org logo
#serialization
Title
# serialization
h

hiperbou

12/19/2017, 11:03 AM
Hello, I'm trying to use kotlinx.serialization with a KotlinJs project without gradle or maven (don't ask :D). I've added the serialization runtime library manually and I can compile the examples. But, IntelliJ shows errors in the code as "unresolved reference kotlinx". I've tried to install the plugin as described in "Working in IntelliJ IDEA" section, but I get this warning "Plugin 'Kotlin-serialization' was already installed". I'm using the latest IntelliJ 2017.3.1. I supose I need to add the serialization plugin to the Kotlin compiler plugin. Can this be achieved?
b

bashor

12/19/2017, 1:14 PM
cc @sandwwraith
s

sandwwraith

12/19/2017, 2:01 PM
If it’s installed in IDEA, it should work out-of-box for JPS(idea build system) compilation. Do you see it in “plugins” list in section?
h

hiperbou

12/19/2017, 3:31 PM
Yes, I can see Kotlin-serialization 0.3 in the list.

https://kotlinlang.slack.com/files/U3XS3MBHB/F8HNEBL30/kotlinxserialization.jpg

s

sandwwraith

12/19/2017, 5:03 PM
Then ‘unresolve reference’ mean that’s something wrong with runtime library. If I did understand you correctly, examples compile and run well, but code in IDEA is red?
h

hiperbou

12/19/2017, 5:06 PM
I did not run it, but I read the generated .js file, and looks ok for me 😄
the kotlin-serialization-runtime-js.js and .meta.js are copied also on the out folder.. everything looks ok, except IDEA complaining about the code
s

sandwwraith

12/19/2017, 5:10 PM
Have you added kotlin-serialization-runtime-js.jar as library in project settings?
h

hiperbou

12/19/2017, 5:10 PM
yes I did
s

sandwwraith

12/19/2017, 5:11 PM
with plugin and runtime library it should work, then. maybe some issue with idea indexes
h

hiperbou

12/19/2017, 5:12 PM
I can ask a coworker to open the project on his computer, to see if he has the same problem. It's a simple example
I had installed manually the old 0.1 plugin, maybe could be something like that..
s

sandwwraith

12/19/2017, 5:13 PM
not sure it’s plugin-related, it’s not responsible for resolving
kotlinx.*
package, only synthetic declarations for your own classes
h

hiperbou

12/19/2017, 5:15 PM
aha
s

sandwwraith

12/19/2017, 5:16 PM
classes from kotlinx.serialization are usual classes, as in any other library
h

hiperbou

12/19/2017, 5:44 PM
My coworker had opened the project with his computer and he has the same issue.. compiles fine, but IDEA complains 😄
s

sandwwraith

12/19/2017, 5:45 PM
🤔
h

hiperbou

12/20/2017, 11:51 AM
Ok, this might help I get this error on running so the compiler plugin is not working for me: "SerializationException: Can't locate companion serializer for class class JoinToGameRequest"
s

sandwwraith

12/20/2017, 11:56 AM
okay. 😞 can you share your sample so I can try to reproduce problem?
s

sandwwraith

12/20/2017, 12:08 PM
Slack says "This file can’t be found" for your link
s

sandwwraith

12/20/2017, 12:14 PM
Thx!
Sorry for late response, I finally found how to help you: In Project Settings -> Libraries, kotlinx-serialization-runtime-js.jar was added as Java library. You have to add it as Kotlin/JS library (last menu item under ). Then it can be indexed by IDEA
h

hiperbou

12/21/2017, 1:31 PM
That's it! Thanks!
I've added the library by right clicking and selecting the "Add as library" and by default it adds as a Java library...
didn't thought of it
Thanks again! 👍
s

sandwwraith

12/21/2017, 1:35 PM
You’re welcome 🙂 Maybe behaviour of “Add as library” worth reporting to youtrack, because it is slightly counter-intuitive
h

hiperbou

12/21/2017, 1:50 PM
mmm.. I still get the error "SerializationException: Can't locate companion serializer for class class XX" I've invalidated cache, restarted and rebuilt the project 😨
s

sandwwraith

12/21/2017, 2:24 PM
Seems plugin wasn’t detected in your project. However, it works in my another JS/JPS project, I’ll take a look at differences
Ah, totally forgot about it. Kotlin/JS compilation in JPS with plugin will be available only in 1.2.20, because corresponding entry points for plugin were merged very recently
You can try 1.2.20-eap
h

hiperbou

12/21/2017, 3:47 PM
I've updated to 1.2.20-eap but I gives another error when deserializing. "TypeError: this is undefined" I'm guessing the line "this.a = a;" should be "$this.a = a;"
s

sandwwraith

12/21/2017, 4:28 PM
could you provide some sample? I think this is related to class inheritance, right?
h

hiperbou

12/21/2017, 4:40 PM
Is the same sample 😄
s

sandwwraith

12/21/2017, 4:42 PM
🤔 🤔 🤔
indeed
seems compatibility between my branch and upstream compiler was broken
h

hiperbou

12/21/2017, 5:05 PM
oh
s

sandwwraith

12/21/2017, 5:07 PM
in 1.2.10, it generates
$this.a = a
h

hiperbou

12/22/2017, 10:20 AM
with 1.2.10-release-IJ2017.3-1 I do not get serializing code generated. It seems that I need to wait for the next release XD
s

sandwwraith

12/22/2017, 10:22 AM
Unfortunately, yes. I meant that gradle build works with 1.2.10. But I see you really want not to mess with gradle 🙂
h

hiperbou

12/22/2017, 11:02 AM
I'm working with some projects at once, and I use gradle on most of them, but with this project with KotlinJS only is not really useful, at the moment, because we had no dependencies, until kotlinx-serialization 😄 Maybe in a near future, when we want to automatize builds, but now using gradle for this project seems like an unneccessary overhead.
12 Views