Skip to content

Added @IgnoreEncodable property wrapper#1567

Merged
NachoSoto merged 1 commit into
mainfrom
ignore-encodable
May 24, 2022
Merged

Added @IgnoreEncodable property wrapper#1567
NachoSoto merged 1 commit into
mainfrom
ignore-encodable

Conversation

@NachoSoto

Copy link
Copy Markdown
Contributor

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).

@NachoSoto NachoSoto requested a review from a team May 11, 2022 20:01
@NachoSoto NachoSoto changed the base branch from main to string-as-data May 11, 2022 22:28
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).
@NachoSoto NachoSoto changed the base branch from string-as-data to main May 11, 2022 22:29

}

extension IgnoreEncodable: Encodable {

@NachoSoto NachoSoto May 12, 2022

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.

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!
}

@NachoSoto NachoSoto merged commit 0132b69 into main May 24, 2022
@NachoSoto NachoSoto deleted the ignore-encodable branch May 24, 2022 01:27
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.
@joshdholtz joshdholtz mentioned this pull request May 26, 2022
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.

2 participants