From db938e1ad8b0b2054a79143aef204d4c8755c039 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 14 Mar 2024 17:07:32 +0300 Subject: [PATCH] add custom json encoder to serializerable meta converter --- .../kotlin/space/kscience/dataforge/meta/MetaConverter.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MetaConverter.kt b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MetaConverter.kt index 8959ae4a..00074525 100644 --- a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MetaConverter.kt +++ b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MetaConverter.kt @@ -135,16 +135,17 @@ public interface MetaConverter: MetaSpec { @DFExperimental public inline fun serializable( descriptor: MetaDescriptor? = null, + jsonEncoder: Json = Json { ignoreUnknownKeys = true }, ): MetaConverter = object : MetaConverter { private val serializer: KSerializer = serializer() override fun readOrNull(source: Meta): T? { val json = source.toJson(descriptor) - return Json.decodeFromJsonElement(serializer, json) + return jsonEncoder.decodeFromJsonElement(serializer, json) } override fun convert(obj: T): Meta { - val json = Json.encodeToJsonElement(obj) + val json = jsonEncoder.encodeToJsonElement(obj) return json.toMeta(descriptor) }