Skip to content

3.2.0

Compare
Choose a tag to compare
@javiersuweijie javiersuweijie released this 10 May 01:55
· 117 commits to master since this release
4f19f38

Added two methods to encode responses into JSON objects

Model -> JSON Object

let token: XenditCCToken = XenditCCToken.init(response: [
            "id": "123",
            "status": "VERIFIED",
            "card_info": [
                "bank": "Test bank"
            ]
])!
let jsonObject = token.toJsonObject()
// ["id": "123", "status": "VERIFIED", "card_info": ["bank": "Test bank"]]

Model -> JSON String (Using the built-in JSONEncoder)

let token: XenditCCToken = XenditCCToken.init(response: [
            "id": "123",
            "status": "VERIFIED",
            "card_info": [
                "bank": "Test bank"
            ]
])!
let encoder = JSONEncoder()
encoder.keyEncodingStrategy = .convertToSnakeCase
let jsonData = try? encoder.encode(token);
let jsonString = String(data: jsonData!, encoding: .utf8)
// "{\"id\":\"123\",\"status\":\"VERIFIED\",\"card_info\":{\"bank\":\"Test bank\"}}"