You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There seems to be a problem decoding annotated struct members into arrays.
When decoding a struct with the DynamicNodeDecoding protocol, it decodes correctly, but when using @ Element, it doesn't.
To highlight the problem, I typed up the following example.
import Foundation
import XMLCoder // .package(url: "https://github.com/CoreOffice/XMLCoder.git", from: "0.17.1")structWorkingRoot:Codable,DynamicNodeDecoding,DynamicNodeEncoding{varnodes:[String]enumCodingKeys:String,CodingKey{case nodes
}staticfunc nodeDecoding(for key:CodingKey)->XMLCoder.XMLDecoder.NodeDecoding{
switch key {caseWorkingRoot.CodingKeys.nodes:.element
default:.elementOrAttribute
}}staticfunc nodeEncoding(for key:CodingKey)->XMLCoder.XMLEncoder.NodeEncoding{
switch key {caseWorkingRoot.CodingKeys.nodes:.element
default:.element
}}}structFailedRoot:Codable{@Elementvarnodes:[String]}// struct Node: Codable {// @Attribute var attr: String?// @Element var value: String//// enum CodingKeys: String, CodingKey {// case attr// case value = ""// }// }letxml="""<root> <nodes attr="test"> First </nodes> <nodes> Second </nodes> <nodes> Third </nodes></root>"""lettestContents= xml.data(using:.utf8)!
// This uses the DynamicNodeDecoding and DynamicNodeEncoding protocols and is working as expected.letcorrectDecoded:WorkingRoot=tryXMLDecoder().decode(WorkingRoot.self, from: testContents)// This uses the @Element decorator and doesn't decode correctly.letwrongDecoded:FailedRoot=tryXMLDecoder().decode(FailedRoot.self, from: testContents)print("This is fine")print(correctDecoded)// WorkingRoot(nodes: ["First", "Second", "Third"])print()print("This isn't")print(wrongDecoded)// FailedRoot(_nodes: XMLCoder.Element<Swift.Array<Swift.String>>(wrappedValue: ["First"]))
The text was updated successfully, but these errors were encountered:
There seems to be a problem decoding annotated struct members into arrays.
When decoding a struct with the DynamicNodeDecoding protocol, it decodes correctly, but when using @ Element, it doesn't.
To highlight the problem, I typed up the following example.
The text was updated successfully, but these errors were encountered: