Thank you so much for the comments Itai and David. Makes perfect sense that the current implementation could be changed in the future. A stream implementation would be awesome and sounds like it’s perfectly doable. <br>A future StructureEncoder has my vote. :-)<br>Thanks again for the feedback!<br>Sincerely,<br>/morten<br><div class="gmail_quote"><div dir="ltr">tir. 25. jul. 2017 kl. 21.08 skrev David Hart <<a href="mailto:david@hartbit.com">david@hartbit.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><blockquote type="cite"><div>On 25 Jul 2017, at 18:45, Itai Ferber via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br class="m_-1008912697738533194Apple-interchange-newline"><div>
<div>
<div style="font-family:sans-serif"><div style="white-space:normal"><p dir="auto">Hi Morten,</p><p dir="auto">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>
The usage of <code style="background-color:#f7f7f7;border-radius:3px;margin:0;padding:0 0.4em" bgcolor="#F7F7F7">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></div></div><div style="word-wrap:break-word"><div>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.</div></div><div style="word-wrap:break-word"><div><br><blockquote type="cite"><div><div><div style="font-family:sans-serif"><div style="white-space:normal"><p dir="auto">We could also introduce something like a general <code style="background-color:#f7f7f7;border-radius:3px;margin:0;padding:0 0.4em" bgcolor="#F7F7F7">StructureEncoder</code>/<code style="background-color:#f7f7f7;border-radius:3px;margin:0;padding:0 0.4em" bgcolor="#F7F7F7">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">PropertyListEncoder</code>/<code style="background-color:#f7f7f7;border-radius:3px;margin:0;padding:0 0.4em" bgcolor="#F7F7F7">PropertyListDecoder</code> currently do something similar.)</p><p dir="auto">So yes, this is under consideration for future API. :)</p><p dir="auto">— Itai</p><p dir="auto">On 25 Jul 2017, at 0:44, Morten Bek Ditlevsen via swift-evolution wrote:</p>
</div>
<div style="white-space:normal"><blockquote style="border-left:2px solid #777;color:#777;margin:0 0 5px;padding-left:5px"><p dir="auto">In the implementation og JSONEncoder and JSONDecoder we have the internal<br>
functionality that encodes Codable types to a structure that is compatible<br>
with JSONSerialization.<br>
The JSONEncoder then calls JSONSerialization on this structure - and<br>
JSONDecoder vice versa.<br>
In some situations it could be nice to just encode or decode to or from<br>
this structure - and not have the final encoding to Data performed. For<br>
instance if you have some library that hands you a structure in this format<br>
and you would like to perform decoding.<br>
<br>
Can anyone else see the relevance of exposing this functionality? It could<br>
be exposed by wrapping _JSONEncoder in a public JSONStructureEncoder or<br>
something similar.<br>
<br>
Sincerely,<br>
/morten<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="color:#777" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></p>
</blockquote></div>
<div style="white-space:normal">
</div>
</div>
</div>
_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div></div></blockquote></div>