Skip to content

Add workaround for Optional JSONEncoding errors#1317

Merged
designatednerd merged 3 commits intomainfrom
fix/json-encoding
Jul 17, 2020
Merged

Add workaround for Optional JSONEncoding errors#1317
designatednerd merged 3 commits intomainfrom
fix/json-encoding

Conversation

@designatednerd
Copy link
Copy Markdown
Contributor

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, the as JSONEncodable would 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 JSONEncodable stuff out in favor of a Codable solution (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!


// 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.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If anyone's got any bright ideas why this fails, I'm all ears.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant