-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[SR-2694] Cannot JSON serialize array with boolean value #648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -285,6 +285,8 @@ private struct JSONWriter { | |||
try serializeDictionary(dict) | |||
} else if let null = obj as? NSNull { | |||
try serializeNull(null) | |||
} else if let boolVal = obj as? Bool { | |||
try serializeNumber(NSNumber(booleanLiteral: boolVal)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NSNumber(value: boolVal) would be better since you are not passing a literal here
1e6d34c
to
47790e1
Compare
@phausler ..Thanks for the review..I have modified the code as per your comments .Please review |
func test_booleanJSONObject() { | ||
do { | ||
let mydata = try JSONSerialization.data(withJSONObject: [true]) | ||
XCTAssertEqual(String(data: mydata, encoding: String.Encoding.utf8),"[1]") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: missing whitespace between arguments
47790e1
to
68d703e
Compare
@swift-ci please test |
@phausler if you're ok with this after the changes, please merge |
https://bugs.swift.org/browse/SR-2694