Hello, I was wondering if you are considering add...
# multiplatform
a
Hello, I was wondering if you are considering adding some warnings around when a developer includes a dependency that targets the JVM? I am currently developing a multiplatform project and chose to use Kategory to build out my core architecture, but it appears it’s a JVM only project right now. While this is fine because I am going to build out Android first, I was wondering what the future may hold for warnings and other build tooling around the detection of such things.
m
I'm not sure Kategory has a js implementation. And as you said, it's reliant on the JVM. Rx might be a slightly easier alternative, as it has both jvm and js (and iOS as well) flavors. However, i think you'd have to write an abstraction layer around it in pure kotlin in order to present a unified interface to the various platforms.
I'm running into the same thing with JSON parsing, and there's no cross platform json parser yet. kotlinx-serialization is meant for mapping to data classes, but i needed something with a pure tree structure, like JsonElement (and it's subclasses) from Gson. I ended up writing my own simple abstraction around it with expect and actual classes for different platforms.
a
I’m aware that there’s no js implementation for Kategory (it’s on their roadmap). What I’m asking is, if there’s some indication of this available without needing to specifically look into it. Having a compiler error for a kotlin-platform-common project which states “this is not compatible with js” would be great. As for Rx, you’re right, however, there’s no kotlin multiplatform version of it, and until such a time I don’t think you could easily implement a unified solution without resorting to more and more abstraction, which moves you away from the unified solution and increases complexity.
e
@mattinger Would you please submit your user case for trees to http://github.com/kotlin/kotlinx.serialization/issues We just recently discussed it and extra use cases would help a lot.
s
Well, it’s not very clear from the docs, but kotlinx.serialization works not only for data classes. However, tree structure parser out-of-box may be useful
m
Basically, i'm building a library to handle some API responses cross platform. Those responses are sent back as hypermedia, so direct data class mapping can be problematic, requiring me to create artificial nodes to represent things like _links, and _embedded. It's much simpler to have a generic data structure, and map the fields manually as needed.
i'm assuming this would just require another KSerializer class, though i haven't inspected the code heavily yet to see what's involved.
e
All is needed is to write
JsonObject
class with a custom
JsonObjectSerializer : KSerializer
implementation attached to it using
@Serializable(with=JsonObjectSerializer::class)
annotation