I'm very new to Kotlin and am curious what magic allows this code to work:
From https://github.com/Kotlin/kotlinx.serialization/blob/e2e764a132c8eebd31208120774baf9a71ec23c7/formats/json/commonTest/src/kotlinx/serialization/SerializerForNullableTypeTest.kt
@Serializable
data class Box(val s: StringHolder?)
val deserialized = Json.decodeFromString<Box>(string)
When the function definition seems to require an initial argument before the encoded JSON string.
https://github.com/Kotlin/kotlinx.serialization/blob/e2e764a132c8eebd31208120774baf9a71ec23c7/formats/json/commonMain/src/kotlinx/serialization/json/Json.kt
public final override fun <T> decodeFromString(deserializer: DeserializationStrategy<T>, string: String): T {
Adding the import below works for me.
import kotlinx.serialization.decodeFromString
Kotlin Official Document
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With