tristanhimmelman / AlamofireObjectMapper

An Alamofire extension which converts JSON response data into swift objects using ObjectMapper
MIT License
2.66k stars 474 forks source link

JSON representation "error" #244

Closed maclacerda closed 3 years ago

maclacerda commented 6 years ago

Hi

I have a problem and I need your help:

This is the json returned from my API:

\"user@mydomain.com.br \", \ "name \": \ "User Full Name \", \ "cellphone \": \ "+ 5531999999999 \", \ "photo \ "\", \ "cpf \", \ "cpf \": \ "\" \ " "\" \ "\" \ "\" \ "\" \ "\" \ "\" \ ": \" \ ", \" birthdate \ ": \" \ ", \" sign_up_complete \ ": false, \" facebook \ ": false, \" password_reseted \

And this my mapping class:

import UIKit import ObjectMapper

class User: Mappable {          let email: String     let name: String     let phone: String     let photo: String     let gender: String     let document: String     let documentEntity: String     let cpf: String     let address: String     let complement: String     let city: String     let state: String     let birthdate: String     let profileCompleted: Bool     let facebookAccount: Bool     let passwordReseted: Bool          required init? (map: Map) {         of {             self.email = try map.value ("email")             self.name = try map.value ("name")             self.phone = try map.value ("cellphone")             self.photo = try map.value ("photo")             self.gender = try map.value ("gender")             self.document = try map.value ("document")             self.documentEntity = try map.value ("general_registry_entity")             self.cpf = try map.value ("cpf")             self.address = try map.value ("address")             self.complement = try map.value ("complement")             self.city = try map.value ("city")             self.state = try map.value ("state")             self.birthdate = try map.value ("birthdate")             self.profileCompleted = try map.value ("sign_up_complete")             self.facebookAccount = try map.value ("facebook")             self.passwordReseted = try map.value ("password_reseted")         catch (let error)             print ("USER PARSE ERROR: \ n \ (error.localizedDescription)")             return nil         }     }          func mapping (map: Map) {}      }

After the parse my object has all attributes populated, but, if i call the user.toJSON () or user.toJSONString () i receive the follow return " {} ".

Now, if i replace mode to map my attributes, using mapping func like your documentation, this works fine.

Do you have any idea of ​​my problem?

Thanks advanced