This repository was archived by the owner on Oct 19, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 11
clarification needed to use with codable classes #3
Copy link
Copy link
Open
Description
Let's say this encoder encodes class with inherintace and depends on default encode(to:) implementation. What i see is that it tries to encode superclass keys into keyed container as expected and then stops. Any ideas ?
Here's the test
func testClassWInheritance() {
class L1: Codable {
init() {
L1_A_KEY="AAAA"
L1_B_KEY=222
L1_D_KEY=4.4
}
var L1_A_KEY: String
var L1_B_KEY: Int
var L1_C_KEY: Int = 2
var L1_D_KEY: Float
private enum CodingKeys: String, CodingKey {
case L1_A_KEY
case L1_B_KEY
case L1_D_KEY
}
}class L2:L1 { override init() { L2_A_KEY="L2222" L2_B_KEY=222333 L2_C_KEY=L3(L3_A_KEY: "L3333", L3_B_KEY: 333) super.init() } required init(from decoder: Decoder) throws { fatalError("init(from:) has not been implemented") try super.init(from: decoder) } var L2_A_KEY: String var L2_B_KEY: Int struct L3: Codable { var L3_A_KEY: String var L3_B_KEY: Int } var L2_C_KEY: L3 } let t = L2() debugPrint(t) let encoder = MyEncoder() XCTAssertNoThrow( try encoder.encode(t))}
(sorry, can't format to look readable. when editing all code formating is intact, but when saved, this happens)
debug result:
"creating keyed container"
"encoding L1_A_KEY"
"encoding L1_B_KEY"
"encoding L1_D_KEY"
Metadata
Metadata
Assignees
Labels
No labels