commonMain.KspoonFormat.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kspoon-korlibs Show documentation
Show all versions of kspoon-korlibs Show documentation
Annotation based HTML to Kotlin class parser with KMP support, jspoon successor
The newest version!
package dev.burnoo.kspoon
import dev.burnoo.kspoon.serializer.kspoonEncodeError
import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.SerializationStrategy
import kotlinx.serialization.StringFormat
import kotlinx.serialization.modules.SerializersModule
internal class KspoonFormat(
private val kspoon: Kspoon,
override val serializersModule: SerializersModule,
private val encodeStringFormatDelegate: StringFormat?,
) : StringFormat {
override fun decodeFromString(deserializer: DeserializationStrategy, string: String): T {
return kspoon.parse(deserializer, string)
}
override fun encodeToString(serializer: SerializationStrategy, value: T): String {
return encodeStringFormatDelegate?.encodeToString(serializer, value)
?: kspoonEncodeError()
}
}