Are custom Encoders/Decoders supported?

To put what @Philippe_Hausler says in another way — JSONDecoder is not a Decoder because the Decoder interface you want to use inside of init(from:) is different from the interface that's useful at code level you're creating a JSONDecoder in. At that top level, you don't necessarily want to deal with containers: instead of creating a JSONDecoder from a data blob, creating a SingleValueDecodingContainer from it, and decoding a value, the preferred level of abstraction and simplicity is decode(_:from:).

From an old discussion:

However, since that discussion, increased benefit for a top-level encoder/decoder concept led to the introduction of TopLevelEncoder/TopLevelDecoder.

3 Likes