Added @IgnoreEncodable property wrapper#1567
Merged
Merged
Conversation
93f478f to
1a449e3
Compare
This allows having properties in an `Encodable` type that won't be encoded. This will be used to storing the `rawData` when decoding our types (see #1496).
1a449e3 to
7d31d9f
Compare
NachoSoto
commented
May 12, 2022
|
|
||
| } | ||
|
|
||
| extension IgnoreEncodable: Encodable { |
Contributor
Author
There was a problem hiding this comment.
A transparent benefit of this is that @IgnoreEncodable conforms to Encodable without relying on Value (because it doesn't actually do anything). Which means that it can be used for types that aren't Encodable (like [String: Any]):
struct Data: Encodable {
@IgnoreEncodable var rawData: [String: Any] // this compiles!
}
aboedo
approved these changes
May 23, 2022
NachoSoto
added a commit
that referenced
this pull request
May 24, 2022
Follow up to #1496. Depends on #1567 and #1568. The solution implemented in #1496 was very simple, but [as pointed out by @joshdholtz](#1496 (comment)), it was only encoding the data that was formally decoded by the `struct`s. We had no test coverage for this, so it went unnoticed. The new solution adds a new field: ```swift @IgnoreEncodable var rawData: [String: Any] ``` Which, together with a new helper method `decodeRawData()`, allows storing all the data to be used by `CustomerInfo`'s `RawDataContainer` implementation. Unfortunately, despite many attempts, I realized that this can't be abstracted into a property wrapper, because a `KeyedDecodingContainer` can't access the parent `Decoder`. That's why the `CustomerInfoResponse` and `CustomerInfoResponse.Entitlement` must manually call this method.
NachoSoto
added a commit
that referenced
this pull request
May 24, 2022
…1565) Follow up to #1496. Depends on ~~#1567, #1568, #1604~~. The solution implemented in #1496 was very simple, but [as pointed out by @joshdholtz](#1496 (comment)), it was only encoding the data that was formally decoded by the `struct`s. We had no test coverage for this, so it went unnoticed. The new solution adds a new field: ```swift @IgnoreEncodable @IgnoreHashable var rawData: [String: Any] ``` Which, together with a new helper method `decodeRawData()`, allows storing all the data to be used by `CustomerInfo`'s `RawDataContainer` implementation. Unfortunately, despite many attempts, I realized that this can't be abstracted into a property wrapper, because a `KeyedDecodingContainer` can't access the parent `Decoder`. That's why the `CustomerInfoResponse` and `CustomerInfoResponse.Entitlement` must manually call this method.
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.
This allows having properties in an
Encodabletype that won't be encoded.This will be used to storing the
rawDatawhen decoding our types (see #1496).