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
NSJSONSerialization JSONObjectWithData: implementation #54
NSJSONSerialization JSONObjectWithData: implementation #54
Conversation
During initalization store the number type in the bit-field in the same way that CFNumberCreate does-so. NSNumber/CFNumber stores its value in a UInt64 (_pad) with associated type information as part of the CFInfo bitfield. Initialization is performed through _CFNumberInit which copies the value bytes into _pad but does not store the type information.
...not the detection itself
guard let string = NSString(data: data, encoding: detectEncoding(data)) else { | ||
throw NSJSONSerializationError.InvalidStringEncoding | ||
} | ||
return try JSONObjectWithString(string as String) |
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 is an implicit conversion that needs to be written as string._swiftObject
Just wanted to note that I think this is a great start, and is going in the direction we want. |
@phausler I hadn't considered the return type conversions. Having looked at it now, I suppose the question here is whether to implement |
I would suspect that something along the lines of what NSPropertyListSerialization had to do will be required as well - see _expensivePropertyListConversion). The route of Any is a bit perilous because Dictionaries and have to then be Any to Any which Any is not Hashable. So some sort of container will have to be used that is Hashable (like the NSObject classes; they are already basically Hashable boxes) |
I see now that |
@phausler I have merged in master and the I did look at implementing |
hashValue for NSString should be relatively easy to implement; CFStringHashNSString is the thing that would do it and it just needs a few CF_SWIFT_CALLV additions. |
I'll take a look at that then. I had assumed __NSCFType was intended to take care of it somehow but if NSString needs its own implementation I'll try to get it done |
The dictionaries here are actually String: Any given the JSON format. That would solve the hashable problem, no? |
|
||
|
||
#if DEPLOYMENT_RUNTIME_OBJC || os(Linux) | ||
@testable import Foundation |
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.
@testable
does not yet seem to be available on Linux targets
TestNSData(), | ||
TestNSTimeZone(), | ||
TestNSScanner(), | ||
TestNSJSONSerialization(), |
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.
Duplicated.
Update recommended toolchain to 2018-12-18-a
Overview
This is a fully-tested RFC4627-compliant implementation of
JSONObjectWithData(_:options:)
.I would like to request feedback about whether this might be accepted in the near future, or conflicts with other plans before I invest more time in improving it.
Still needed
NSJSONReadingAllowFragments
implementationJSONObjectWithStream(_:options:)
implementation - depends on unimplementedNSInputStream
Notes
The underlying parser is implemented as an internal type which would be well suited to reuse in possible-future API changes.