PerfectlySoft / Perfect

Server-side Swift. The Perfect core toolset and framework for Swift Developers. (For mobile back-end development, website and API development, and more…)
https://www.perfect.org
Apache License 2.0
13.84k stars 945 forks source link

JSON as an Enum #9

Closed colemancda closed 8 years ago

colemancda commented 8 years ago

As in

https://github.com/PureSwift/SwiftFoundation/blob/develop/Source/JSON.swift

Way safer, more Protocol Oriented Programming

Danappelxx commented 8 years ago

Speaking of which, why should we reinvent the wheel? Many people have done great work regarding foundation-free Swift. At the very least, shouldn't Perfect be modular so that we can use whichever server/orm/templates we want? Maybe I should move this to a separate issue...

pepyakin commented 8 years ago

I prefer for server to be serialization-agnostic, if it will still be easy of use.

kaandedeoglu commented 8 years ago

I think the main intent here is to have both Perfect server and Perfect client use the same JSON decoding, allowing models to be shared between the backend and the frontend codebases.

Of course, this doesn't stop Perfect from adopting @colemancda's Swiftier suggestion.

kjessup commented 8 years ago

We provided the JSON encoding/decoding classes as a convenience as that functionality is generally a required part of any backend service. That said, the Perfect system as it stands today does not use encoding/decoding as part of its normal operations. In the examples and in the apps we have in beta using Perfect the JSON responses are created through mustache templates and any input to the server is received as standard url-encoded or multi-part form submissions. So it's certainly possible for one to swap in their own preferred serialization mechanism. We tried to keep things flexible such that you wouldn't be required to add anything extra to your iOS apps and could opt to only use the backend server system.

The Tap Tracker example does use JSONDecode, basically to show how it works. Personally, in real apps, I opt to use the iOS built-in JSON decoding merely in an effort to keep the app's footprint small and reduce dependancies (the Authenticator example iOS app uses NSJSONSerialization).

We do intend to introduce some features which would use, at the least, JSON encoding (as opposed to decoding). We will revisit the state of those classes before we being development on these aspects.

I appreciate the feedback and examples of better approaches to handling JSON serialization.

iamjono commented 8 years ago

Closing this issue for now as a lot of effort has gone into increasing the modularity of Perfect, and the ability to flip in your own JSON encoder/decoder options is there regardless. We would like to hear your ongoing feedback on this and other issues, so please join us on the PerfectlySoft Gitter group! Gitter