<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Hi Tony,</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Jul 13, 2560 BE, at 23:20, Tony Parker <<a href="mailto:anthony.parker@apple.com" class="">anthony.parker@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space;">Hi Pitiphong,<br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Jul 13, 2017, at 12:37 AM, Pitiphong Phongpattranont via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">Hi swift-evolution,</div><div class=""><br class=""></div><div class="">I have a few feedbacks on SE-0166 and SE-0167. I’m a library maintainer of a Swift library for my company. We’re a payment gateway service and have a wide range of support library in many programming languages (including Swift).</div><div class=""><br class=""></div><div class="">Here’re my feedbacks</div><div class=""><br class=""></div><div class="">1. The auto synthesized code from the Swift compiler is a great feature but I’m not sure if this is a bug. If I have a property of type Dictionary<String, Any>, the auto synthesize doesn’t work and I need to implement the init(from decoder:) method manually (with code like `metadata = try container.decodeIfPresent([String: Any].self, forKey: .metadata)`) I will report this as a bug on <a href="http://bugs.swift.org/" class="">bugs.swift.org</a></div><div class="">2. In JSONEncoder/Decoder, you can specify the date parsing behavior since there’re many ways to represent this. My thought is that that should apply to `DateComponents` too since there are also many ways to represent `DateComponent` e.g. the ISO8601 also has a spec for parsing the date or time which should map to `DateComponents` type in Swift. And since the DateComponents already conforms to the Decodable protocol so I cannot (and should not) override the system behavior so I need to do the decoding manually on every types that have a property of DateComponents type</div></div></div></blockquote><div class=""><br class=""></div>Would you be willing to share an example of what your JSON looks like and what your resulting DateComponents struct looks like here?</div></div></div></blockquote>Sure, AFAIC <a href="https://en.wikipedia.org/wiki/ISO_8601" class="">ISO 8601</a> support the date only string too and this is what my service is using for represent the date (that not include time) for example “2017-07-13” represents the date of July 13th, 2017 in Gregorian calendar.</div><div>The current behavior of JSONEncoder is encode each of the DateComponents properties into their owns keys in the JSON not using the ISO 8601. I think the way that the design of date encoding/decoding of JSONEncoder with `dateEncodingStrategy` property would also fit into this too.</div><div><br class=""></div><div>The example of my JSON data is </div><div><br class=""></div><div>````</div><div>{<br class=""> "object": "schedule",<br class=""> "id": "schd_test_584zfswqzu5m40sycxc",<br class=""> "start_date": "2017-05-30",<br class=""> "end_date": "2018-05-20",<br class=""> "next_occurrence_dates": [<br class=""> "2017-07-16",<br class=""> "2017-08-01",<br class=""> "2017-08-16",<br class=""> ],<br class=""> "created": "2017-05-30T08:37:10Z”<br class="">}</div><div>````</div><div>Note that the created property is `Date Time (Date)` The start_date and end_date are Date (DateComponents) and next_occurrence_dates is an array of Date (Array<DateComponents>).</div><div><br class=""></div><div><br class=""></div><div><blockquote type="cite" class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space;"><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">3. Since Swift has an associated value enum while many others doesn’t have (including JavaScript which is the mother of JSON), I design our library to use the power of associated value enum as much as possible. This means that there are some types/properties those are built from a multiple properties of a JSON object.</div></div></div></blockquote><div class=""><br class=""></div><div class="">Yah, it’s certainly reasonable to adopt Decodable on an enum with an associated value, but I’m not sure if we should try to expand the automatic synthesis to handle this case or just ask these kinds of types to implement Decodable manually. We’re hoping that the synthesis covers a lot of cases, but it was a non-goal to attempt to cover 100% of the possible scenarios this way. We focused a lot on making the API usable on its own too.</div><div class=""><br class=""></div></div></div></blockquote><br class=""><div>I understand your point. I also agree with you. That’s just my wish list for Swift feature but it must not out weight other perspective of design and implementation.</div><div><br class=""></div><div>Also I find some interesting approach for this and I want to ask you for your opinion. For now I don’t make those enum to adopt Decodable protocol since those need to be built from the multiple key value pairs from the JSON. I decided to extract the raw value in `init(from decoder:)` and build the value manually.</div><div><br class=""></div><div>But I saw someone post some code snippet by making those enum to adopt Decodable protocol and extracts the necessary key values pairs But they decode the enum by calling</div><div><br class=""></div><div>`status = try ChargeStatus(from: decoder)`</div><div><br class=""></div><div>For me personally, the adopting Decodable protocol part is great but the code to decode looks fishy to me.</div><div><br class=""></div><div>Do you have any opinion on this approach?</div><div><br class=""></div><div>Thank you</div><div>Pitiphong P.</div><br class=""><blockquote type="cite" class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space;"><div class=""><div class="">- Tony</div><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">For example: The status property of Charge is an enum which has a associated value case for `failure` status. So in my library it is built from the `status` and `failureMessage` properties in JSON. For now there is no simple or automatic way (auto synthesized code from Swift Compiler) to do this in Decodable. I need to implement it manually on every types those have this similar properties. And TBH I still don’t have any ideas on how to design the Decodable to support this feature.</div><div class=""><br class=""></div><div class="">Those are my feedbacks on SE-0166 and SE-0167 for now. I hope my feedbacks would help the Swift and Swift community</div><div class=""><br class=""></div><div class="">Best regards,</div><div class="">Pitiphong Phongpattranont</div><div class=""><br class=""></div>> Hi swift-evolution,<br class="">> <br class="">> Over the course of the past few weeks, we’ve been gathering feedback<br class="">> about the outcome of<br class="">> [SE-0166](<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0166-swift-archival-serialization.md" class="">https://github.com/apple/swift-evolution/blob/master/proposals/0166-swift-archival-serialization.md</a>)<br class="">> and<br class="">> [SE-0167](<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0167-swift-encoders.md" class="">https://github.com/apple/swift-evolution/blob/master/proposals/0167-swift-encoders.md</a>)<br class="">> (both internally and externally), and we gathered a collection of<br class="">> updates that we’re going to introduce to the proposals and to the<br class="">> implementation.<br class="">> <br class="">> Attached is rendered HTML (I don’t want to make your mail clients<br class="">> unusable like last time!) that lays out what we’d like to do. We’re<br class="">> not looking to do a full review of these changes, but if you have<br class="">> feedback or questions, we’re happy to get responses here.<br class="">> <br class="">> Please note that some of these features have already been implemented<br class="">> (the new error types, some of the optionality changes, collection<br class="">> conformances, etc.), but we are receptive to comments on all of it. The<br class="">> existing proposals will also be updated to incorporate these updates.<br class="">> <br class="">> Thanks for all of your feedback!<br class="">> <br class="">> — Itai<br class="">> <br class="">> <br class="">> </div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></blockquote></div></body></html>