<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8">
</head>
<body>
<div style="font-family:sans-serif"><div style="white-space:normal">
<p dir="auto">Hi Jon,</p>
<p dir="auto">I just joined this mailing list and have tried to catch up on the history of this thread, so please excuse me if I’ve missed something.</p>
<p dir="auto">I’m sorry the Codable API at the moment does not answer your needs — you’re clearly not the only one who’s run into this, so let’s see how we can work together to make the API better for everyone.<br>
For one thing, in the case of grabbing a subtree of JSON as "unevaluated" or "unmapped" (as it appears to be in the metadata case), it should be fairly simple to add a <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">JSONDecoder.UnevaluatedJSON</code> type that will allow you to essentially decode that part of the tree as an <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">Any</code>. <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">JSONDecoder</code> would have knowledge of this type and would be able to return the subtree inside of it — you’d decode a property as <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">JSONDecoder.UnevaluatedJSON.self</code> and access the contents through <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">var value: Any?</code>, or something similar. This would be simple additive API, which although might not make it in the upcoming betas, should be fairly simple introduce. Would this solve that use case?</p>
<p dir="auto">We’re also working on improving <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">NSISO8601DateFormatter</code>. I don’t think I saw it in any of your emails — what specific use case are you looking for that it doesn’t at the moment support?</p>
<p dir="auto">— Itai</p>
<p dir="auto">On 23 Jun 2017, at 9:24, Jon Shier via swift-users wrote:</p>
</div>
<div style="white-space:normal"></div>
<blockquote style="border-left:2px solid #777; color:#777; margin:0 0 5px; padding-left:5px"><div id="3C5DA499-CC76-4203-A2BF-ACD1E8FEF35B"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">David:<div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>I never called the design silly (though I think it’s inadequate for some important usage and makes some strange decisions), I was referring to the fact that the (apparent) official solution can’t actually decode all of the JSON people use. It’s the same reason I brought up NSISO8601DateFormatter. After years of using third party libraries or writing your own, limited, implementation, finally, finally there was an official solution from Apple. The official 8601 date formatter. Only, come to find out, it doesn’t actually handle all of 8601 and those third party libraries or custom implementations are still required if you venture outside supported scenarios. I’m concerned about the same thing happening here. Now, if JSONDecoder isn’t actually intended to serve as a general JSON parsing solution, which I think would be surprising to a lot people, then fair enough. Apple and the Swift team just need to be far more clear that that’s the case, rather letting everyone believe otherwise. And frankly, if that’s the case, I think a huge opportunity has been missed. At the same time, if / when an official solution for JSON parsing comes out, or an actual JSON representation, how will it interact with the previous implementation?</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>These concerns, and the general concerns I expressed during the evolution review (which still exist) aside, this is fixable, if the Swift team is interested in doing so. However, if the limitations of JSONDecoder aren’t even seen as limitations, or interest in fixing them aren’t there, then there’s little point to continuing the discussion. Something as simple as an additional decode(_ type: from: Any) on JSONDecoder would solve the issues with decoding partially deserialized blobs or representations from other APIs. Something to help represent Any in Codable types might be useful, though I recognize that there isn’t any way to currently differentiate between Codable types and those just used by JSON. </div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>All of that said, my concerns mainly lie within the JSON realm. Codable works great for serialization to disk or other scenarios where I can just deal with the Data result and not have to worry about weakly typed intermediate results. I’ll certainly be using it everywhere I can. And I’m super happy that conformance is generated by the compiler rather than manually, like we had to do with Objective-C for over a decade. Even the JSON side is useful if I can control both sides of the API, which makes Swift on the server very powerful.</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>So if I seem overly strident in my expression here it’s because I experience the pain of consuming poorly designed JSON in Swift on practically a daily basis and had hoped that a native implementation would alleviate that. That it doesn’t, for me and others, currently, is very disappointing. That the Swift team doesn’t seem to see the current limitations as important or at all is doubly so, since it seems like these issues will never be fixed. </div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Jon</div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 23, 2017, at 4:34 AM, David Hart <<a href="mailto:david@hartbit.com" class="">david@hartbit.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class="Apple-interchange-newline">On 23 Jun 2017, at 03:45, Jon Shier via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:<br class=""><br class=""></div><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class=""><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>I’m sorry, are you complaining about my use of Codable instead of more precisely referring to the JSON endcode/decode functionality based on it in Foundation, or are you honestly trying to say that said functionality was never intended to be a general purpose JSON solution? If it’s not actually intended to handle all JSON you should probably call it something else.</div></blockquote><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Hi Jon,</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">First of all, I'd like to point out that I've found your tone to be quite rude. Calling the design of Codable, that has gotten a lot of work from Apple and swift-evolution, as silly is insulting and can leave people hurt. If you have found it lacking, please say so: we're all here to discuss any feedback people have had with Swift. But please do so with respect for the people and the work behind it.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Now, concerning Codable, I find its name quite apt. It was never intended to be used a full JSON parser but as a strongly-typed Swift equivalent of Objective-C's NSCoding, which is nothing more than a framework for serializing and deserializing types into different file formats.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">David.</div><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class=""><div class=""><div class="">Jon<br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Jun 22, 2017, at 9:42 PM, Greg Parker <<a href="mailto:gparker@apple.com" class="">gparker@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space;"><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jun 22, 2017, at 6:00 PM, Jon Shier via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space;"><br class=""><div class=""><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>My main concern here is that, as Swift’s official JSON parsing method, Codable should be able to handle any JSON representation and use and it doesn’t.<span class="Apple-converted-space"> </span></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">Is this true? Is Codable intended to be Swift's official JSON parsing system? Is Codable intended to be a general-purpose JSON parsing system? </div><div class=""><br class=""></div><div class="">My understanding was that Codable was designed to serialize Swift types, not to be able to import arbitrary JSON text into Swift nor to interoperate with every existing JSON API.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">-- </div><div class="">Greg Parker <span class="Apple-converted-space"> </span><a href="mailto:gparker@apple.com" class="">gparker@apple.com</a> Runtime Wrangler</div><div class=""><br class=""></div><div class=""><br class=""></div></div></div></div></blockquote></div><br class=""></div></div></blockquote><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-users mailing list</span><br class=""><span class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" class="">https://lists.swift.org/mailman/listinfo/swift-users</a></span></div></blockquote></div></blockquote></div><br class=""></div></div></div></blockquote>
<div style="white-space:normal">
<blockquote style="border-left:2px solid #777; color:#777; margin:0 0 5px; padding-left:5px">
</blockquote><blockquote style="border-left:2px solid #777; color:#777; margin:0 0 5px; padding-left:5px"><p dir="auto">_______________________________________________<br>
swift-users mailing list<br>
swift-users@swift.org<br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" style="color:#777">https://lists.swift.org/mailman/listinfo/swift-users</a></p>
</blockquote></div>
<div style="white-space:normal">
</div>
</div>
</body>
</html>