I have an API that doesn't return a response. In t...
# serialization
m
I have an API that doesn't return a response. In the client code I do have a response class, which is an empty class. In GSON I had a deserializer that just returned an instance of this empty class, but I am wondering how to handle it with kotlinx.serialization? How to "deserialize" an empty response? I have nothing to put into the
descriptor
of my custom deserializer since the deserializer doesn't read anything.
s
Could the response not be Unit instead of some class?
m
Ideally yes, but legacy code. While changing that pattern would be good, for now I am looking to just change the serialisation library from GSON to kotlinx.serialisation without changing the pattern.
Turns out kotlinx.serialization doesn't need a serializer for empty classes at all. I just had to mark it as
@Serializable
and that's it, it works.
🌟 1