Repository navigation
Sanitize dictionaries before serialization - #82
Merged
Merged
Conversation
benjackwhite
left a comment
Contributor
There was a problem hiding this comment.
Some thoughts on how we should best handle this, thinking ahead to what the feedback will be if someone gets into this situation.
benjackwhite
requested changes
Oct 30, 2023
benjackwhite
left a comment
Contributor
There was a problem hiding this comment.
This looks great functionally but feels like something that 100% needs tests
benjackwhite
approved these changes
Nov 2, 2023
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
posthog-ios/PostHog/Models/PostHogEvent.swift
Lines 33 to 34 in 19064a4
Codabletypes 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
JSONSerializationas 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
AnyCodableas well but entered the rabbit whole of https://github.com/asensei/AnyCodable/tree/masterJSONSerialization.isValidJSONObjectalways 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: