Is there a way to properly deserialize a JSON response to Swift objects resp. using DTOs as containers for fixed JSON APIs?
Something similar to http://james.newtonk
HandyJSON
is another option to deal with JSON for you. https://github.com/alibaba/handyjson
It deserials JSON to object directly. No need to specify mapping relationship, no need to inherit from NSObject. Just define your pure-swift class/struct, and deserial JSON to it.
class Animal: HandyJSON { var name: String? var id: String? var num: Int? required init() {} } let jsonString = "{\"name\":\"cat\",\"id\":\"12345\",\"num\":180}" if let animal = JSONDeserializer.deserializeFrom(jsonString) { print(animal) }