Codable types only would be awesome but the interoperability with ObjC is suboptimal.
Using Generics would be ideal as well but again bad interoperability with ObjC.
I guess we can improve this in the future if we see it but I'd not write tons of code right now, the older version relies onJSONSerialization as well.
What does this PR do?
Sanitize dictionaries before serialization
Where should the reviewer start?
How should this be manually tested?
Any background context you want to provide?
I've tried multiple approaches for proper sanitization but all of them have edge cases or get overly complex. Similar thoughts as here https://github.com/PostHog/posthog-ios/blob/19064a4f25e74e50604b9954d2e0a18f779d7397/PostHog/Models/PostHogEvent.swift#L33-L34
Codable
types only would be awesome but the interoperability with ObjC is suboptimal.Using Generics would be ideal as well but again bad interoperability with ObjC. I guess we can improve this in the future if we see it but I'd not write tons of code right now, the older version relies on
JSONSerialization
as well.I checked https://github.com/SwiftyJSON/SwiftyJSON/blob/master/Source/SwiftyJSON/SwiftyJSON.swift It just fails if there's a nonserializable type. Also, https://swiftunboxed.com/stdlib/json-decoder-decodable/ but generics are not well played. Tried to implement my own version of
AnyCodable
as well but entered the rabbit whole of https://github.com/asensei/AnyCodable/tree/masterJSONSerialization.isValidJSONObject
always requires an Object or Array, so I cannot just use it for each value of the dict.What are the relevant tickets?
Screenshots or screencasts (if UI/UX change)
Questions: