Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS: Expand AnyType to handle deeply nested AnyType for beacon encoding #519

Merged
merged 5 commits into from
Oct 1, 2024

Conversation

hborawski
Copy link
Contributor

@hborawski hborawski commented Sep 27, 2024

AnyType decoded as a part of the asset tree did not have AnyTypeDecodingContext to allow for [String: Any] decoding, that context is now added in BaseRegistry when decoding the asset tree

Including complex metadata for beacons would not reencode when passing the beacon from Swift to JSC in all scenarios.

{
  "asset": {
    "id": "action-1",
    "type": "action",
    "exp": "{{count}} = {{count}} + 1",
    "label": {
      "asset": {
        "id": "action-label-1",
        "type": "text",
        "value": "Clicked {{count}} times"
      }
    },
    "metaData": {
      "beacon": {
        "array": [{
          "key": "value"
        }],
        "string": "value"
      }
    }
  }
}

In this scenario, this metadata would be decoded by the ActionAsset, which includes AnyType for the beacon metadata. When sending this decoded type through BeaconContext.beacon, the encoding was failing for the nested keys, as the entire beacon key would be decoded as AnyType with .anyDictionary([String: Any]). Encoding the Any values failed.

CustomEncodable did not work against Any, so instead, I decode Any as AnyType which is then encodable, and can be used as the backing type for encoding

Change Type (required)

Indicate the type of change your pull request is:

  • patch
  • minor
  • major

Does your PR have any documentation updates?

  • Updated docs
  • No Update needed
  • Unable to update docs

Version

Published prerelease version: 0.9.2-next.0

Changelog

🐛 Bug Fix

  • iOS: Expand AnyType to handle deeply nested AnyType for beacon encoding #519 (@hborawski)

Authors: 1

@hborawski hborawski added the patch Increment the patch version when merged label Sep 27, 2024
@@ -154,6 +167,12 @@ struct CustomEncodable: CodingKey {
self.stringValue = key
if let encodable = encodable as? Encodable {
self.data = encodable
} else if
let encodable,
let data = try? JSONSerialization.data(withJSONObject: encodable, options: .fragmentsAllowed),
Copy link
Contributor Author

@hborawski hborawski Sep 27, 2024

Choose a reason for hiding this comment

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

.fragmentsAllowed lets us encode String here as a top level type in JSON (normally JSON would need to be [] or {} as the top level type), as we dont know what the value type will be

Copy link

codecov bot commented Sep 27, 2024

Codecov Report

Attention: Patch coverage is 96.29630% with 3 lines in your changes missing coverage. Please review.

Project coverage is 91.91%. Comparing base (d67483b) to head (ad827d6).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
ios/core/Tests/Types/Generic/AnyTypeTests.swift 93.87% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #519      +/-   ##
==========================================
+ Coverage   91.89%   91.91%   +0.01%     
==========================================
  Files         341      341              
  Lines       27232    27311      +79     
  Branches     1944     1944              
==========================================
+ Hits        25026    25103      +77     
- Misses       2192     2194       +2     
  Partials       14       14              
Flag Coverage Δ
91.91% <96.29%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

nancywu1
nancywu1 previously approved these changes Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch Increment the patch version when merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants