XMLCoder icon indicating copy to clipboard operation
XMLCoder copied to clipboard

Empty date tag cannot be decoded since version 0.10.0

Open TJDev opened this issue 5 years ago • 0 comments

I am using a xml api with a possible nullable date tag. Up to version 0.9.0 it was no problem decoding the data but since 0.10.0, I am getting the following error:

valueNotFound(Foundation.Date, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "date", intValue: nil)], debugDescription: "Expected Date value but found null instead.", underlyingError: nil))

I reproduced the behavior with the following struct ...

import Foundation

struct DateTest : Codable {
    let name: String
    let date: Date?
    let nullableString: String?
}

... and test.

func testNullableDateParsing() throws {
    let decoder = XMLDecoder()
    
    let xml = """
        <container>
            <name>Null date</name>
            <date></date>
            <nullableString></nullableString>
        </container>
    """
    
    let data = xml.data(using: .utf8)!
    
    XCTAssertNoThrow(try decoder.decode(DateTest.self, from: data))
}

P.S.: Is it normal that when a decoding error occurs inside a sub struct, that the original error is hidden?

TJDev avatar Dec 12 '20 13:12 TJDev