<!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 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>
<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>
swift-evolution@swift.org<br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="color:#777">https://lists.swift.org/mailman/listinfo/swift-evolution</a></p>
</blockquote></div>
<div style="white-space:normal">
</div>
</div>
</body>
</html>