add docs to mapper serialization and allow to use them as supertypes

This commit is contained in:
2023-03-09 22:21:11 +06:00
parent f5f7511781
commit b3f468f901
4 changed files with 159 additions and 1 deletions

View File

@@ -5,7 +5,15 @@ import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
class MapperSerializer<I, O>(
/**
* Use this serializer when you have serializable type [I] and want to map it to some [O] in process of
* serialization/deserialization
*
* @param base Serializer for [I]
* @param serialize Will be used in [serialize] method to convert incoming [O] to [I] and serialize with [base]
* @param deserialize Will be used in [deserialize] method to convert deserialized by [base] [I] to [O]
*/
open class MapperSerializer<I, O>(
private val base: KSerializer<I>,
private val serialize: (O) -> I,
private val deserialize: (I) -> O