Dumitru Preguza
06/12/2025, 12:35 PMMichael Paus
06/12/2025, 12:55 PMDumitru Preguza
06/12/2025, 1:00 PMbishiboosh
06/12/2025, 1:12 PMbishiboosh
06/12/2025, 1:13 PMjw
06/12/2025, 1:13 PMbishiboosh
06/12/2025, 1:15 PMjw
06/12/2025, 1:17 PMbishiboosh
06/12/2025, 1:21 PMbishiboosh
06/12/2025, 1:23 PMDumitru Preguza
06/16/2025, 8:42 PMToml.loadFromFile(path = “resources/file.toml”)
As I see, the library makers provide just the parser, but I need the full support for seamless usage, I need somehow to get the string from the file located in “./shared/commonMain/resources/application.toml/yaml/json/etc” first.
To be honest at this point it’s a lot easier to write a Kotlin Class/Object directly in the shared module and hardcode all the config fields there,
Just wanted to know how the KMP community handles this case
Chat Gpt suggested to impl the reading of the file from each platform via expect/actual and use the parser in the shared code, but it’s getting too verbose, maybe there is already a starter mobile pack for boilerplate or something similar?bishiboosh
06/17/2025, 5:34 AM<http://kotlinx.io|kotlinx.io>
, and then it's quite easy to plug with the serializationMichael Paus
06/17/2025, 12:38 PMval configString = Res.readBytes("files/config.json").decodeToString()
val config: Config = jsonFormat.decodeFromString(configString)
You could even reduce that to a single line if you want to. And the file has to reside in:
[…]/src/commonMain/composeResources/files/config.json
You do not even need Okio or anything else for the IO part. This assumes of course that you can use Compose resources. If that is not the case you have to otherwise get the config string.Dumitru Preguza
06/17/2025, 12:45 PMDumitru Preguza
06/17/2025, 12:48 PMMichael Paus
06/17/2025, 12:48 PMMichael Paus
06/17/2025, 12:50 PMbishiboosh
06/17/2025, 12:51 PMMichael Paus
06/17/2025, 12:52 PMDumitru Preguza
06/17/2025, 12:52 PMbishiboosh
06/17/2025, 12:59 PMkotlinx-serialization-json-okio
exists for Okio (I thought there was one for kotlinx.io but I'm mistaken), and it's quite easy to do the same for some other formats (at least I know I've done in my projects)Dumitru Preguza
06/17/2025, 10:28 PMDumitru Preguza
06/17/2025, 10:30 PMjw
06/17/2025, 10:35 PMjw
06/17/2025, 10:36 PMDumitru Preguza
06/17/2025, 10:51 PM