-
-
Notifications
You must be signed in to change notification settings - Fork 313
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
WIP: adding virtual object serialization method to entities #642
Conversation
I feel like it's a bit too loose and complicated. This would be easy to shoot oneself in the foot and might lead to some confusion. I have recently seen an interesting pattern that is very easy to implement, and that I would like to propose as a potential alternative solution. The idea is to simply add a It seems to that it would strike a nice balance between flexibility and simplicity. |
Oh I like that idea! Do you know of any public projects that use that strategy? I'd love to see some example code for implementing it.
…--
Josh Harms
On Mon, Jun 7, 2021, at 03:15, Clement Gutel wrote:
I feel like it's a bit too loose and complicated. This would be easy to shoot oneself in the foot and might lead to some confusion.
I have recently seen an interesting pattern that is very easy to implement, and that I would like to propose as a potential alternative solution.
The idea is to simply add a `bool SparseUpdate { get; set;} ` property to all entity objects.
When serializing the object, ShopifySharp would check the value of this property.
If false, then all properties are serialized.
If true, then only non-null properties are serialized.
It seems to that it would strike a nice balance between flexibility and simplicity.
What do you think?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#642 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AASOE7FISAQFMQNMXS7TCDLTRR53TANCNFSM46FLQLOQ>.
|
The QuickBooks API uses this pattern, but the difference is that it's handled by the API itself. Here is an example to update just the MiddleName: For ShopifySharp, we'll have to handle it in the library and change the serialization accordingly. Here is what I'm thinking. Add the following to
I guess it could be nullable, although a default value of false seems appropriate. Create a new Add this converter to the ShopifyObject class. |
What would we do in cases where you specifically want to send null with a sparse update, for whatever reason? Something like this:
|
That would not work and that is one downside. If you want to send a null, you must first load the object via the api first and send a full update. |
I'm experimenting with adding custom object serialization to all of our entity models. Open to feedback here, but what I'm envisioning is a virtual
ToJsonDictionary
method on the baseShopifyObject
class that all of our models inherit. The base implementation will use the currentObjectExtensions.ToDictionary
method to serialize itself, and if developers need custom serialization for a certain object they can override the method.One thing to consider for this implementation is that it still does not give the developer control of the entire object that gets sent during requests to Shopify. For example, when creating an order we need to send
{"order": { ... }}
. The developer can customize what's inside the order itself, but they have no control of the outer body. Is that okay? Technically if they need to control that part they can just create their own service implementation and override whatever method they're trying to customize.Things that would be nice to have but not necessary for this particular pull request:
Something to consider when implementing the goal of this pull request. Open to feedback here!