matthewcheok / JSONCodable

Hassle-free JSON encoding and decoding in Swift
MIT License
602 stars 66 forks source link

Empty in an JSONEncodable object result in missing key in toJSON #51

Closed lightsprint09 closed 7 years ago

lightsprint09 commented 8 years ago
struct Foo {
    let bar: Array<Int> = []
}

extension Foo: JSONEncodable {
    func toJSON() throws -> AnyObject {
        return try JSONEncoder.create({ (encoder) -> Void in
            try encoder.encode(bar, key: "bar")
        })
    }
}

This should result in the following

{ 
   "bar": []
}

and not

{ 
}

Corresponding to JSONEncodable L196