vapor-community / json

Convenience wrapper for Foundation JSON.
MIT License
30 stars 18 forks source link

Foundation.JSONEncoder() encoded bool gets converted to double #65

Open leonidas-o opened 7 years ago

leonidas-o commented 7 years ago

Using: Vapor 2.3.0 (JSON 2.2.1)

    struct JSONStruct: Codable {
        var is_disabled: Bool
    }
    let jsonStruct = JSONStruct(is_disabled: false)
    let jsonData = try Foundation.JSONEncoder().encode(jsonStruct)
    let json = try JSON(bytes: jsonData)
    print(json)

When looking at the json variable and the print out, is_disabled has been converted to a double of 0.0 although it should stay false.

tanner0101 commented 6 years ago

Unfortunately Swift's Foundation JSON (before 4.0) forces us to have fuzzy bool/double/int support. If you are using Swift 4, you can opt for Codable instead. We will support that natively in Vapor 3.