How are custom formats types supposed to be handle...
# serialization
d
How are custom formats types supposed to be handled/represented? SerialInfo annotation? inline class? Custom serializer for annotation?
b
I saw this sort of pattern in the Json format:
Copy code
interface MyFormatEncoder : Encoder {
    fun encodeMyType(value: MyType)
}

interface CompositeMyFormatEncoder : CompositeEncoder {
    fun encodeMyTypeElement(descriptor: SerialDescriptor, index: Int, value: MyType)
}

fun Encoder.asMyFormatEncoder(): MyFormatEncoder =
    this as? MyFormatEncoder ?: throw MyEncodingException(
        "This serializer can only be used with MyFormat format. " +
            "Expected MyFormatEncoder, but got ${this::class}"
    )

// And the same for a MyFormatDecoder
Then just a custom serializer that uses encoder.asMyFormatEncoder() when encoding. No annotations, and doesn't matter if it's inline
d
That seems reasonable.