diff --git a/CHANGELOG.md b/CHANGELOG.md index 50220cc2871..a80f27c4420 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.17.4 +* `Serialization`: + * `Mapper`: + * Module inited + ## 0.17.3 * `Common`: diff --git a/serialization/mapper/build.gradle b/serialization/mapper/build.gradle new file mode 100644 index 00000000000..7c54502f100 --- /dev/null +++ b/serialization/mapper/build.gradle @@ -0,0 +1,7 @@ +plugins { + id "org.jetbrains.kotlin.multiplatform" + id "org.jetbrains.kotlin.plugin.serialization" + id "com.android.library" +} + +apply from: "$mppProjectWithSerializationPresetPath" diff --git a/serialization/mapper/src/commonMain/kotlin/MapperSerializer.kt b/serialization/mapper/src/commonMain/kotlin/MapperSerializer.kt new file mode 100644 index 00000000000..c18343deb82 --- /dev/null +++ b/serialization/mapper/src/commonMain/kotlin/MapperSerializer.kt @@ -0,0 +1,22 @@ +package dev.inmo.micro_utils.serialization.mapper + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +class MapperSerializer( + private val base: KSerializer, + private val serialize: (O) -> I, + private val deserialize: (I) -> O +) : KSerializer { + override val descriptor: SerialDescriptor = base.descriptor + + override fun deserialize(decoder: Decoder): O { + return deserialize(base.deserialize(decoder)) + } + + override fun serialize(encoder: Encoder, value: O) { + base.serialize(encoder, serialize(value)) + } +} diff --git a/settings.gradle b/settings.gradle index 6d422fe4e63..ec21091c550 100644 --- a/settings.gradle +++ b/settings.gradle @@ -37,6 +37,7 @@ String[] includes = [ ":serialization:base64", ":serialization:encapsulator", ":serialization:typed_serializer", + ":serialization:mapper", ":startup:plugin", ":startup:launcher",