Skip to content

Created AnyDecodable#1568

Merged
NachoSoto merged 1 commit into
mainfrom
any-decodable
May 16, 2022
Merged

Created AnyDecodable#1568
NachoSoto merged 1 commit into
mainfrom
any-decodable

Conversation

@NachoSoto

Copy link
Copy Markdown
Contributor

This will be used to decode the entire data in JSON for the new implementation of RawDataContainer in #1496.

@NachoSoto NachoSoto requested a review from a team May 11, 2022 22:42
Comment thread Sources/Misc/AnyDecodable.swift Outdated

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.

This allows decoding all the data in JSON into [String: Any], which normally wouldn't be Decodable.

This will be used to decode the entire data in JSON for the new implementation of `RawDataContainer` in #1496.

@taquitos taquitos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎈🐐

self = .null
} else if let value = try? container.decode(String.self) {
self = .string(value)
} else if let value = try? container.decode(Int.self) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I shouldn't be surprised, yet I am- if you pass in 2.5 it won't try to decode as an Int, it will work as a Double. That's neat.

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.

Types are nice

@NachoSoto NachoSoto merged commit fd4b276 into main May 16, 2022
@NachoSoto NachoSoto deleted the any-decodable branch May 16, 2022 23:12
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