While making a custom encoder/decoder, it is possi...
# serialization
f
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:
Copy code
class MyEncoder : NamedValueEncoder {
     fun encodeInt() { ... }
      ...
     fun encodeUUID() { ... }
}
class MyDecoder : NamedValueDecoder {
      fun decodeInt() { ... }
       ...
      fun decodeUUID() { ... }
And then users can do:
Copy code
@Serializable
data class OtherFormats(val uuid: UUID)
Instead of:
Copy code
@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)
)
d
There's a
@Serializer(forClass=UUID::class)
you can look into.
f
That requires you to do
@Serializable(with = UuidSerializer::class)
When
UuidSerializer
is the name of a class annotated with
@Serializer(forClass=UUID::class)