-
Notifications
You must be signed in to change notification settings - Fork 614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect serialization of class defined in an external library after upgrade to 0.5.1 #153
Comments
Was just about to create what I believe to be the exact same issue. However, I have pinpointed it to any classes defined in an external library. This also does not seem specific to Kotlin/JS, as I am compiling to the JVM. The following unit tests demonstrate this:
Could you update the issue title accordingly? Another interesting finding: open classes serialize correctly. I presume the reason behind this is that open classes are serialized using the |
A temporary workaround which works is defining the serializer explicitly:
|
I believe the same bug also causes inherited classes from external libraries to be deserialized incorrectly. In one module define:
In another, define:
Serializing this outputs |
Fixed with new plugin update |
Verified. This fixes all issues I reported on here (including the inheritance issue). Thanks for the quick fix! |
When I have @serializable data class defined in an external library:
@serializable
data class LibraryClass(val time: Long)
and I use it in my project (which of course uses the library):
@serializable
data class MyClass(val kdate: LibraryClass)
after serializing:
val x = MyClass(LibraryClass(100))
console.log(JSON.stringify(x))
I get:
{"kdate":"LibraryClass(time=100)"}
instead of:
{"kdate": { "time": 100} }
It worked OK in version 0.5.0 (and Kotlin/JS 1.2.41)
It also works OK if the class is defined in the same project (not in the library).
And also it works correctly if I serialize this class directly:
val x = LibraryClass(100)
console.log(JSON.stringify(x))
{"time": 100}
The text was updated successfully, but these errors were encountered: