Open Dino4674 opened 5 years ago
I also tried deserializing date by using JSONDecoder with custom formatter and it works. Here is a sample code:
struct AB: Codable {
let date: Date?
}
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .formatted(.apiDateFormatter)
let data = "{ \"date\": \"2019-08-05T08:41:06.590Z\" }".data(using: .utf8)
let object = try? decoder.decode(AB.self, from: data!)
print("Object: \(object)")
From this it looks like I've been configuring up JSONDecoder
correctly and that the problem is in CodableAlamofire library when using this decoder.
When using this
DateFormatter
separately, I can successfully deserialize date string with it:If I use the same formatter when calling
.responeDecodableObject(decoder: decoder)
, model properties (of Date type) are set to nil.Is there any more setup that I am not aware of? Thanks