evermeer / AlamofireJsonToObjects

An Alamofire extension which converts JSON response data into swift objects using EVReflection
Other
161 stars 28 forks source link

.description outputs a boolean as a number (0 or 1) #33

Closed Dbigshooter closed 8 years ago

Dbigshooter commented 8 years ago

Hi there,

I'm trying to map some simple JSON:

{"id":121,"active":false}

In the following model:

class MyObject : EVObject {

    var id : Int = 0
    var active: Bool = false
...

However the boolean maps to an int, I get the following output of the mapping:

MyObject {
   id = 121
   active = 0
}

Am I missing something?

evermeer commented 8 years ago

When I run the following test:

func testIssue33() {
        let json = "{\"id\":121,\"active\":false}"
        let object = MyObject(json: json)
        let newJson = object.toJsonString()
        print("back to json = \(newJson)\n\nobject description = \(object)")
    }

The output will be:

back to json = {
  "id" : 121,
  "active" : false
}

object description = MyObject {
   hash = 9956788539511
   id = 121
   active = 0
}

When you just print the object it will call the .description function on it to get the string representation. I will now have a look to see why it's outputting 0 instead of false...

evermeer commented 8 years ago

Ah true... The boolean will be put in the dictionary as a NSCFBoolean which has a NSNumber as it's base. Let me see if I can make the .description function output it as true/false instead of a number.

screen shot 2016-10-20 at 20 21 49
evermeer commented 8 years ago

This is fixed in EVReflection 3.3.3