<https://youtrack.jetbrains.com/issue/KT-23449>
# javascript
m
c
Without looking into the whole code: how are you deserializing the objects?
If you're just trying to deserialize them into
News
, they will lose all information except for the date. You have to add additional type field and deserialize into the correct type based on that field.
m
Forgot to mention: I use Kotlin serialization, but I suspected this might be a problem so I repack all objects from this API:
Copy code
// HACK: Serialization objects does not correspond correctly to real objects so we need to repack them all
    override suspend fun getNewsData(): NewsData {
        val str = httpGet(Endpoints.news)
        val parsed = json.parse<NewsData>(str)
        val articles = parsed.articles.map { Article(it.id, ArticleData(it.data.title, it.data.subtitle, it.data.imageUrl, it.data.url, it.data.occurrence), it.dateTime) }
        val infos = parsed.infos.map { Info(it.id, InfoData(it.data.title, it.data.imageUrl, it.data.description, it.data.sources, it.data.url, it.data.author, it.data.authorUrl), it.dateTime, it.accepted) }
        val puzzlers = parsed.puzzlers.map { Puzzler(it.id, PuzzlerData(it.data.title, it.data.level, it.data.question, it.data.answers, it.data.correctAnswer, it.data.explanation, it.data.author, it.data.authorUrl), it.dateTime, it.accepted) }
        val newsData = NewsData(articles, infos, puzzlers)
        return newsData
    }
c
I think that might be the problem:
val parsed = json.parse<NewsData>(str)
m
I am not junior developer. My passes articles, infos and puzzlers in separate properties
c
OK, I take it back, read the whole thing.
m
But at this moment it works.
getNewsData
returns correct lists and all objects there are created in Kotlin/JS (as you can see above)
I also suspect that the reason of this problems might be in serialization, but if it takes place after this repacking then it must be also Kotlin/JS problem.
c
Have you tried the checks after removing
@Serializable
?
b
@marcinmoskala does it work after “repack”?
m
No
@czyzby I need this because I pass this object through API and I need to deserialize
b
is it enough to build and run KotlinAcademyApp from master to reproduce?
m
Steps to reproduce: use
news
instead of
newsData
in
showList
function on
NewsComponent
c
I figured, just curious if
@Serializable
is causing the issue.
I planned on using
kotlinx-serialization
in a toy project, this feels like a major bug.
b
@marcinmoskala would be nice if you could push a branch with code to reproduce
m
5 minutes
b
It would be even simpler/better if you could deploy it somewhere
if you don’t minify it
m
It is wired, but it works now
Maybe I haven't cleaned some caches before
I will test it more
b
Honestly, I think it’s some problem in kotlinx.serialization and I’d expected that “repacked” version works.
@sandwwraith is it the known bug?
m
It looks so. I must have had wrong code in caches. I have a problem with mutliplatform Kotlin/JS project what when I change something in
common
or in
common-client
then I must clean it, because just
run
doesn't use new code.
s
Are you sure that you didn’t confuse
kotlin.js.JSON
with
kotlinx.serialization.json.JSON
? The former is known to produce “not fair” kotlin objects
m
I use https://github.com/Kotlin/kotlinx.serialization because it is multiplatform project