-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Description
| Previous ID | SR-12275 |
| Radar | rdar://problem/59830261 |
| Original Reporter | xavier.lowmiller (JIRA User) |
| Type | Bug |
| Status | Resolved |
| Resolution | Done |
Environment
I tested this in the 5.1.4 Swift Docker Container from https://hub.docker.com/\_/swift
Additional Detail from JIRA
| Votes | 0 |
| Component/s | Foundation |
| Labels | Bug |
| Assignee | @spevans |
| Priority | Medium |
md5: 824ef3e9951a0e0fa1f7b095708f76f3
relates to:
- SR-6163 JSONDecoder cannot decode RFC 7159 JSON
Issue Description:
Consider the following program:
import Foundation
let data = 2
do {
let stored = try String(data: JSONEncoder().encode(data), encoding: .utf8)!
print(stored)
print(try JSONDecoder().decode(Int.self, from: Data(stored.utf8)))
} catch {
print(error)
}On macOS, this will work: The `JSONEncoder` produces a `Data` with contents `2`.
On Linux, this prints the following error:
invalidValue(2, Swift.EncodingError.Context(codingPath: [], debugDescription: "Top-level Int encoded as number JSON fragment.", underlyingError: nil))