Thread
#serialization
    Fudge

    Fudge

    3 years ago
    While making a custom encoder/decoder, it is possible to support additional data formats so that users don't need to do
    @Serializable(with = ...::class)
    whenever they use the data format? For example, support UUID:
    class MyEncoder : NamedValueEncoder {
         fun encodeInt() { ... }
          ...
         fun encodeUUID() { ... }
    }
    class MyDecoder : NamedValueDecoder {
          fun decodeInt() { ... }
           ...
          fun decodeUUID() { ... }
    And then users can do:
    @Serializable
    data class OtherFormats(val uuid: UUID)
    Instead of:
    @Serializable
    data class OtherFormats(@Serializable(with = UuidSerializer::class) val uuid: UUID)
    (where
    UuidSerializer
    is the name of a class annotated with
    @Serializer(forClass=UUID::class)
    )
    Dominaezzz

    Dominaezzz

    3 years ago
    There's a
    @Serializer(forClass=UUID::class)
    you can look into.
    Fudge

    Fudge

    3 years ago
    That requires you to do
    @Serializable(with = UuidSerializer::class)
    When
    UuidSerializer
    is the name of a class annotated with
    @Serializer(forClass=UUID::class)