-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
JSON Encoding based on JSONValue #2987
Conversation
@swift-ci test |
@inline(__always) func setObject(for key: String) -> Object { | ||
switch self.dict[key] { | ||
case .encoder: | ||
preconditionFailure("For key \"\(key)\" an encoder has already been created.") |
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.
is it safe to precondition here (and other spot around this)? i.e no user action can cause this?
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.
This shall lead to a crash because of a programmer error and closely mimics the Darwin Foundation behavior. It is not possible to create a json array or a json dictionary at the same time for the same key.
if #available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) { | ||
return .string(_iso8601Formatter.string(from: date)) | ||
} else { | ||
fatalError("ISO8601DateFormatter is unavailable on this platform.") |
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.
hmmm I think we can use regular formatter with right pattern to achieve iso8601, no?
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.
I see it now
} | ||
bytes.append(._closebracket) | ||
case .object(let dict): | ||
if #available(OSX 10.13, *), options.contains(.sortedKeys) { |
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.
ditto, should be supported on linux afaik
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.
I see it now
Sources/Foundation/JSONEncoder.swift
Outdated
case nestedArray(Array) | ||
case nestedObject(Object) | ||
|
||
class Array { |
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.
Could we name this something more specific? I get it's a private type but that case nestedArray(Array)
threw me for a second.
c96f6be
to
8660270
Compare
@swift-ci test |
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.
Gave it another read through LGTM
cc @millenomi |
After #2966 and #2985, this is the last step to make JSON Encoding and Decoding much more performant on Linux.