mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-22 08:13:49 +00:00
add mapper serializer
This commit is contained in:
parent
4be1d93f60
commit
f5f7511781
@ -2,6 +2,10 @@
|
||||
|
||||
## 0.17.4
|
||||
|
||||
* `Serialization`:
|
||||
* `Mapper`:
|
||||
* Module inited
|
||||
|
||||
## 0.17.3
|
||||
|
||||
* `Common`:
|
||||
|
7
serialization/mapper/build.gradle
Normal file
7
serialization/mapper/build.gradle
Normal file
@ -0,0 +1,7 @@
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
@ -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<I, O>(
|
||||
private val base: KSerializer<I>,
|
||||
private val serialize: (O) -> I,
|
||||
private val deserialize: (I) -> O
|
||||
) : KSerializer<O> {
|
||||
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))
|
||||
}
|
||||
}
|
@ -37,6 +37,7 @@ String[] includes = [
|
||||
":serialization:base64",
|
||||
":serialization:encapsulator",
|
||||
":serialization:typed_serializer",
|
||||
":serialization:mapper",
|
||||
":startup:plugin",
|
||||
":startup:launcher",
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user