Does this work with KMP? #245
-
Quick question: Can I use this library with KMP? The moment I add the dependency in commonMain for ktoml, i get the following error:
Here's the error:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hey there! That's a great question 😄 The As mentioned in the readme:
You can read the file on your platform and then use the library directly with your string or sequence of strings: // Add extensions from 'kotlinx' lib to your project:
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.serializer
// Add com.akuleshov7:ktoml-core to your project:
import com.akuleshov7.ktoml.deserialize
@Serializable
data class MyClass(/* your fields */)
// To deserialize TOML input in string format (separated by newlines '\n')
// No need to provide serializer() explicitly if you use the extension method from
// <kotlinx.serialization.decodeFromString>
val resultFromString = Toml.decodeFromString<MyClass>(/* string with a TOML input */)
val resultFromList = Toml.decodeFromString<MyClass>(serializer(), /* sequence with lines of strings with a TOML input */) |
Beta Was this translation helpful? Give feedback.
@realityexpander, Ktoml utilizes an API from Kotlinx Serialization, which can be found at https://github.com/Kotlin/kotlinx.serialization. The anticipated structure for implementations involves having only a decodeFromString(string) method, consistent with other Kotlin serializers.
Given our status as a multiplatform library, considerations must be made for various targets. Implementing native features unrelated to serialization, such as file reading (typically handled by separate libraries), can pose challenges. For instance, in KotlinJS, file reading is inherently not feasible.
Nevertheless, in ktoml, we've chosen to expand this functionality for platforms where we comprehend the workin…