Skip to content

[SR-4849] Fixed integer widths not supported as JSON objects on Linux #47426

@alblue

Description

@alblue
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

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions