TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | Apache 2 |
ReleasedLast Release | Oct 2015 |
SPMSupports SPM | ✗ |
Maintained by corinne krych.
This module currently build with Xcode 7 and supports iOS7 [1], iOS8, iOS9.
Serialize ‘Swift’ objects back-forth from their JSON representation the 'easy way’.
Project Info | |
---|---|
License: | Apache License, Version 2.0 |
Build: | Cocoapods |
Documentation: | https://aerogear.org/docs/guides/aerogear-ios-2.X/ |
Issue tracker: | https://issues.jboss.org/browse/AGIOS |
Mailing lists: | aerogear-users (subscribe) |
aerogear-dev (subscribe) |
Note [1]: Cocoapod central repo supports dynamic library from iOS8+. If you want to deploy on iOS7, use areoger-ios-http fom master source with its podspec pointing to iOS7.
Here is a typical example usage:
class Contact : JSONSerializable {
var first: String?
var last: String?
var addr: Address?
required init() {}
class func map(source: JsonSZ, object: Contact) {
object.first <= source["first"]
object.last <= source["last"]
object.addr <= source["addr"]
}
}
class Address: JSONSerializable {
var street: String?
var poBox: Int?
var city: String?
var country: String?
var arr:[String]
required init() {}
class func map(source: JsonSZ, object: Address) {
object.street <= source["street"]
object.poBox <= source["poBox"]
object.city <= source["city"]
object.country <= source["country"]
}
}
// construct object
let address = Address()
address.street = "Street"
address.poBox = 100
address.city="New York"
address.country = "US"
let user = User()
user.first = "John"
user.last = "Doe"
// assign Address to User
user.addr = address
// initialize serializer
let serializer = JsonSZ()
// serialize ToJSON
let JSON = serializer.toJSON(user)
// ..send json to server
// serialize fromJSON
let user = serializer.fromJSON(JSON, to:User.self)
// user now should be initialized
println(user.first!)
...
As long as your model object implements the JSONSerializable
protocol and its required methods of init
and map
, the JsonSZ
class should be able to serialize and deserialize your objects to JSON. The library supports all the primitive types including arrays and dictionaries plus relationship between the objects (as shown by the User, Address example above). Head over to our unit tests for more examples usage.
Give it a go and let us know if it does help you on your projects!
Last, we would like to give appreciation and credit to the existing serialization libraries of ObjectMapper and SwiftMapper for giving us an initial bootstrap and ideas to base our development of this library. Thank you guys!
To add the library in your project, you can either use Cocoapods or manual install in your project. See the respective sections below for instructions:
Follow these steps to add the library in your Swift project:
git submodule add https://github.com/aerogear/aerogear-ios-jsonsz.git
aerogear-ios-jsonsz
folder, and drag the AeroGearJsonSZ.xcodeproj
into the file navigator in Xcode.AeroGearJsonSZ.framework
.+
button at the top left of the panel and select “New Copy Files Phase”. Rename this new phase to “Copy Frameworks”, set the “Destination” to “Frameworks”, and add AeroGearJsonSZ.framework
.For more details about the current release, please consult our documentation.
If you would like to help develop AeroGear you can join our developer’s mailing list, join #aerogear on Freenode, or shout at us on Twitter @aerogears.
Also takes some time and skim the contributor guide
Join our user mailing list for any questions or help! We really hope you enjoy app development with AeroGear!
If you found a bug please create a ticket for us on Jira with some steps to reproduce it.