-
Notifications
You must be signed in to change notification settings - Fork 104
Type-safe parsing of JSON response #1127
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, remove PBM prefix in new Swift classes.
Since we are switching converting JSON to Swift. can we use advantages of Codable?
Its possible to use codable, but in my experience Codable tends to be too strict for most uses. In our case I think we want to prioritize successful parsing of response objects over enforcing strict conformance to the response spec. If for example for some field the response contains You could loosen strictness in these cases, but this is not the default behavior and you would need to write your own custom decoding logic and the end result is usually harder to read and more error prone than alternatives. |
@YuriyVelichkoPI Can we hold up on this PR and prioritize merging in the SPM migration PRs? Those PRs include the swift migration part of this PR, and I'd like to avoid having to do a rebase/merge. I can add back in the custom class feature afterwards. |
Thanks for the clarification. Makes sense. We can try Codable later. |
Changes:
JSONParsing.swift
keep the model object code simple and ensure consistent and type-safe conversions to and from JSON.Additions:
Fixes:
-Made
PBMORTBAbstractResponse.ext
nullable to handle the case in-[PBMORTBAbstractResponse initWithJsonDictionary:extParser]
where it does not get set. This case previously existed in tests, but after migratingPBMORTBBidExt
to swift, the nil objc class instance instead became an uninitialized Swift class instance and crashed.-[PBMAbstractCreative handleClickthrough:sdkConfiguration:completionHandler:onExit:]