<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On 25 Jul 2017, at 18:45, Itai Ferber 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="">
<meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8" class="">
<div class="">
<div style="font-family:sans-serif" class=""><div style="white-space:normal" class=""><p dir="auto" class="">Hi Morten,</p><p dir="auto" class="">This is something we’ve considered adding and may do so in the future — however, this will require additional API review and will not make it in time for the Swift 4.0 release.<br class="">
The usage of <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7" class="">JSONSerialization</code> as the serialization backend is a current implementation detail, and may change in future releases; it would, for instance, be more efficient to read/write JSON as we encode/decode, instead of trying to collect the entire object graph before performing the next step.</p></div></div></div></div></blockquote>As a side note, if this could be pushed even further to allow encoding/decoding to/from a Stream, it would allow me to use Codable on a project where I’m parsing JSON files in the hundreds of Mbs. I have no choice but to use a streaming parser.<br class=""><blockquote type="cite" class=""><div class=""><div class=""><div style="font-family:sans-serif" class=""><div style="white-space:normal" class=""><p dir="auto" class="">We could also introduce something like a general <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7" class="">StructureEncoder</code>/<code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7" class="">StructureDecoder</code> which performs this conversion, as this might be useful outside of just JSON. (For instance, <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7" class="">PropertyListEncoder</code>/<code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7" class="">PropertyListDecoder</code> currently do something similar.)</p><p dir="auto" class="">So yes, this is under consideration for future API. :)</p><p dir="auto" class="">— Itai</p><p dir="auto" class="">On 25 Jul 2017, at 0:44, Morten Bek Ditlevsen via swift-evolution wrote:</p>
</div>
<div style="white-space:normal" class=""><blockquote style="border-left:2px solid #777; color:#777; margin:0 0 5px; padding-left:5px" class=""><p dir="auto" class="">In the implementation og JSONEncoder and JSONDecoder we have the internal<br class="">
functionality that encodes Codable types to a structure that is compatible<br class="">
with JSONSerialization.<br class="">
The JSONEncoder then calls JSONSerialization on this structure - and<br class="">
JSONDecoder vice versa.<br class="">
In some situations it could be nice to just encode or decode to or from<br class="">
this structure - and not have the final encoding to Data performed. For<br class="">
instance if you have some library that hands you a structure in this format<br class="">
and you would like to perform decoding.<br class="">
<br class="">
Can anyone else see the relevance of exposing this functionality? It could<br class="">
be exposed by wrapping _JSONEncoder in a public JSONStructureEncoder or<br class="">
something similar.<br class="">
<br class="">
Sincerely,<br class="">
/morten<br class="">
_______________________________________________<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" style="color:#777" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></p>
</blockquote></div>
<div style="white-space:normal" class="">
</div>
</div>
</div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>