Add workaround for Optional JSONEncoding errors#1317
Merged
designatednerd merged 3 commits intomainfrom Jul 17, 2020
Merged
Conversation
designatednerd
commented
Jul 17, 2020
|
|
||
| // WORKAROUND: For reasons I don't totally understand, when the underlying type is `Any`, | ||
| // even though all of these conform to `JSONEncodable`, the `as JSONEncodable` above | ||
| // fails, and we need to handle them individually. |
Contributor
Author
There was a problem hiding this comment.
If anyone's got any bright ideas why this fails, I'm all ears.
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.
This is basically a band-aid on #1305 and similar bugs, which could occur when using a custom JSON scalar and trying to persist it to the cache. If the type of the typealiased JSON was
[String: Any?], which is expected, theas JSONEncodablewould fail to recognize several types that have that conformance in an extension, and those types need to be unwrapped manually.This is a band-aid rather than a permanent fix because once I can get the Swift codegen stuff going again, I'm going to rip all this
JSONEncodablestuff out in favor of aCodablesolution (you can see a preview of the more flexible part of this in the JSON type I'm using in the Codegen lib).But that's gonna be a hot minute, so band-aid it is!