BSON icon indicating copy to clipboard operation
BSON copied to clipboard

Codable with Class hierarchy does not seem to work

Open marcblanchet opened this issue 3 years ago • 1 comments

class A: Codable { var a: String } class B: A { var b: String } if one properly do implement CodingKeys enum and encode and decode in the subclass, the Foundation JSONDecoder/Encoder (as well as other third-party decoders such as XMLCoder, CodableCSV, ...) do correctly encode/decode properties of both class A and class B if one encode/decode a B object. However, BSON does not seem to be working in this scenario. It seems to not call/use the parent class container.

marcblanchet avatar Jul 23 '20 21:07 marcblanchet

Hello @marcblanchet, thanks for the bug report! I've never tested this particular usecase. The BSON Encoder/Decoder were written when Codable was still in a development snapshot, so this part was never revisited after other implementations & docs were written.

Joannis avatar Jul 24 '20 07:07 Joannis