Future of Codable and JSON-Coders in Swift 6: Hoping for a rework

There are several other threads about Codable, like this one: Serialization in Swift
Most of these drawback along with solutions are already discussed, but the final shape is not determined AFAIK.

Not only because it is an open class but also because it is a mutable class.
+1 here, the lack of Sendability is a problem.

+1 here

I would also add the lack of access to raw storage inside coding / decoding functions.

For now we have a situation that current Codable implementation is a good default while making it better require other language improvements / features and research. My own suggestion that most of this can be addressed after Swift 6 release.
So for now we have a reasonable default implementation, but specific needs can be solved:

  • performance / dictionary coding by 3d party libraries
  • Sendability by immutable sendable wrapper
  • Default Values by different tricks
    ...

In my projects I've implemented some error handling solutions that allows to know Coding failure reason, which Type, which property and why, failed object json string, request url, file, line and other information. This info is sent to monitoring system so all unexpected failures are caught and developers even don't need to open IDE to understand mapping failure reason in most cases.
I hope most of this will come out of the box some day.

3 Likes