3.2.0
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\"}}"