Open openradar-mirror opened 8 years ago
Modified: 2016-08-20T20:14:30.469660
Modified: 2016-08-20T20:14:30.469660
Modified: 2016-08-20T20:14:30.469660
Modified: 2016-08-20T20:14:30.469660
Modified: 2016-08-20T20:14:30.469660
Modified: 2016-08-20T20:14:30.469660
Modified: 2016-08-20T20:14:30.469660
Modified: 2016-08-20T20:14:30.469660
Modified: 2016-08-20T20:14:30.469660
Description
When using Swift 2.3, NSJSONSerialization serializes the dictionary ["first": true, "second": false] as:
{"first":true,"second":false}
When using Swift 3.0, JSONSerialization serializes the same dictionary as:
{"first":1,"second":0}
Some web service APIs, including the Gmail API, will reject 1 or 0 when expecting a boolean value.
Steps to reproduce:
In a Swift 2.3 project, run this unit test. It will pass.
func testJson() {
}
In a Swift 3.0 project, run this unit test
func testJson() {
}
Expected Results:
I would expect the Swift 3.0 unit test to pass.
Actual Results:
The Swift 3.0 unit test fails. The value of jsonString is:
{"first":1,"second":0} - or - {"second":0,"first":1}
Configuration:
I encountered this using Xcode 8.0 beta 6 while developing an iOS app. I can reproduce the bug both on the simulator and on an iPod Touch running iOS 10 beta 7 (14A5345a). I am not certain, but I believe this is a change in behavior since Xcode 8.0 beta 5.
Additional Notes:
I think this is an important bug. Many app developers write apps that talk to web services outside of their control.
Thank you for taking a look.
Product Version: Xcode Version 8.0 beta 6 (8S201h) on Sierra (macOs 10.12 Beta (16A294a)) Created: 2016-08-20T17:46:12.867340 Originated: 2016-08-20T00:00:00 Open Radar Link: http://www.openradar.me/27937005