The future of serialization & deserialization APIs

On the top of my head, we sometimes need to customize the decoding of "blank values", for example:

  • Decoding a non-optional String in such a way that null, absent are decoded as "".
    This happens when the app wants to encode the lack of information as "".

  • Decoding a String? in such a way that null, absent, "", maybe even strings only made of white spaces, are decoded as nil.
    This happens when the app wants to encode the lack of information as nil.

Some for Int, Double, etc. where 0 could take place of "".

All of that was customizable and possible with Decodable (often verbose, maybe with the help of a dedicated value type, but possible).

I wish it were possible for apps to provide custom decoding strategies without the need to write a macro.

5 Likes