-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Description
Previous ID | SR-4849 |
Radar | None |
Original Reporter | @alblue |
Type | Bug |
Status | Resolved |
Resolution | Duplicate |
Additional Detail from JIRA
Votes | 0 |
Component/s | |
Labels | Bug |
Assignee | None |
Priority | Medium |
md5: 8df5f3d2bd14addf4919e5266cb9f0cd
duplicates:
- SR-4475 JSONSerialization cannot serialize UInt8 on Linux
Issue Description:
The check in isValidJSONObject on Linux only checks for generic-width ints (Int, UInt) and not explicit sized widths (e.g. Int8)
// object is Swift.String, NSNull, Int, Bool, or UInt
if obj is String || obj is NSNull || obj is Int || obj is Bool || obj is UInt {
return true
}
As a result, this code behaves differently on Linux and Darwin:
import Foundation
let i64:Int64 = 1
let i:Int = 1
print( [JSONSerialization.isValidJSONObject(["int64":i64]),
JSONSerialization.isValidJSONObject(["int":i])])
On Darwin, this prints
[true, true]
On Linux, this prints
[false, true]
Adding explicitly sized integer widths (Int64, Int8 etc.) into the isValidObject should fix the problem.
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.