<div dir="ltr">Hi Vladimir,<div><br></div><div>FYI, I also wanted to decode directly from NSDictionary and NSArray, so I made <a href="https://github.com/norio-nomura/ObjectEncoder">https://github.com/norio-nomura/ObjectEncoder</a>.<br></div><div>It is a simpler implementation than JSONEncoder/JSONDecoder because it does not contain any functions to treat specific type specially.</div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-11-10 1:37 GMT+09:00 Vladimir Kushelkov via swift-corelibs-dev <span dir="ltr"><<a href="mailto:swift-corelibs-dev@swift.org" target="_blank">swift-corelibs-dev@swift.org</a>></span>:<br><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>1. Sometimes it is contently to be able to decode a struct or an object from <span style="color:rgb(36,41,46);background-color:rgb(255,255,255)">a Foundation object (either NSArray or NSDictionary) that
produce a valid JSON.</span></div>
<div><span style="background-color:rgb(255,255,255)"><font color="#24292e">For example, if I use a 3d party library that provides </font></span><span style="background-color:rgb(255,255,255)"><font color="#24292e"><i>NSDictionary</i> to
me. Due to </font></span><span style="color:rgb(36,41,46)"><i>JSONDecoder</i> decodes only from
<i>Data</i>,</span><span style="background-color:rgb(255,255,255)"><font color="#24292e"> in the first place I have to convert
<i>NSDictionary</i> to <i>Data</i> in order to use </font></span><font color="#24292e">the one so far. But the decoder does the back action first thing.</font></div>
<div><font color="#24292e">I created </font><a href="https://github.com/apple/swift/pull/12791" target="_blank">Pull Request</a><font color="#24292e">, that was closed.</font></div>
<div><font color="#24292e"><br>
</font></div>
<div><font color="#24292e"><br>
</font></div>
<div><font color="#24292e">2. Is it possible to use </font><i style="color:rgb(36,41,46)">JSONDecoder</i><font color="#24292e"> when I don’t know the type of a particular property of the required type?</font></div>
<div><font color="#24292e">For instance, if I develop a library that allows bi-directional communication between server and client. The library wraps transmitted data into an internal object in a way that one of the object’s properties is
the</font><font color="#24292e"> data. So, the type of the property is unknown inside the library. I want to decode the internal object with JSONDecoder, but I can’t specify the type of one property.</font></div>
<div><br>
</div>
</div>
<br>______________________________<wbr>_________________<br>
swift-corelibs-dev mailing list<br>
<a href="mailto:swift-corelibs-dev@swift.org">swift-corelibs-dev@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-corelibs-dev" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>corelibs-dev</a><br>
<br></blockquote></div><br></div>