-
Notifications
You must be signed in to change notification settings - Fork 39
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
Pass in JsonSerializerOptions to generic methods #187
Pass in JsonSerializerOptions to generic methods #187
Conversation
@MichaelDeutschCoding do you want to add a test for coverage & show the use case? |
I added unit tests. Thanks for fixing that embarrassing typo for me! 🤦♂️ |
@MichaelDeutschCoding do you want to fix the errors? |
Yeah, sorry I was being lazy and just doing it directly in the browser. That does tend towards silly mistakes. I did just clone it locally and run the tests after fixing them. Verified it's working properly now. Let me know if you'd like more tests and or documentation for this. |
/// <typeparam name="T">The type retrieved</typeparam> | ||
/// <returns>The object requested</returns> | ||
/// <remarks><seealso href="https://redis.io/commands/json.get"/></remarks> | ||
Task<T?> GetAsync<T>(RedisKey key, string path = "$"); | ||
Task<T?> GetAsync<T>(RedisKey key, string path = "$", JsonSerializerOptions? serializerOptions = default); |
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.
Technically these API changes are binary breaks, if you overlay the new DLLs you'll get missing member exceptions - as the calling applications will need to recompile. NRedisStack is still pre-1.0 so avoiding breaks is still "best effort" I'd say so there's a few options:
- Add the new signature as an extra overload rather than as an optional parameter
- Rev the minor version to 0.10.0
- YOLO - just merge - probably won't break anyone
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.
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.
I don't really have the context to know which of those options makes the most sense; this is my first contribution to the code base. I'm happy to implement any of those approaches, if you can just give me the direction you'd like to take.
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.
@slorello89
To create another signature where serializerOptions is not optional, we will have to do it like this:
T? Get<T>(RedisKey key, JsonSerializerOptions serializerOptions, string path = "$");
What changes the order of the original function (path after key), I think it's better to leave serializerOptions optional.
WDYT?
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.
You would just reset this line, and add a new method with:
Task<T?> GetAsync<T>(RedisKey key, string path = "$", JsonSerializerOptions serializerOptions);
as the signature.
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.
@slorello89 I didn't understand how this is possible, an optional variable should come at the end
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.
I don't know how bad it would be breaking binary/reflection users by changing the method signature, but personally it would feel weird to me to add an additional separate method with a mandatory JsonSerializerOptions, when that parameter is itself optional in the JsonSerializer method we're calling.
If the version number is bumped, does that provide enough "warning" if it does indeed break anyone's use flow?
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.
Honestly, I didn't understand why it breaks.
If the variable we added is optional, anyone who used the function without JsonSerializerOptions
can continue to use it in exactly the same way because the variable is optional.
@slorello89 what do you say?
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.
@shacharPash - @MichaelDeutschCoding is correct - adding optional parameters are compiler-compatible but not binary-compatible. You would need to recompile your application if you use the method in question. See my comments above, as this is still not 1.0+ I think all three options are valid (reset the signature, bump minor, or YOLO), however, if we were post 1.0 I'd insist on option 1 as this is a very minor change to make a major revision for and you really shouldn't propagate binary breaks in minors/patches.
Codecov ReportAll modified lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #187 +/- ##
=======================================
Coverage 94.03% 94.03%
=======================================
Files 82 82
Lines 5127 5127
Branches 483 483
=======================================
Hits 4821 4821
Misses 180 180
Partials 126 126
☔ View full report in Codecov by Sentry. |
Also, once this change may be requiring bumping the version, would we want to consider adding the option to pass in JsonSerializerOptions to the Serialize methods as well? Certain features like PropertyNamingPolicy, DefaultIgnoreCondition, and Converters (in particular the ability to add a JsonStringEnumConverter) may be very useful to some people. |
@MichaelDeutschCoding Not sure I understood, where else did you think of adding JsonSerializerOptions? |
Optional paramter at the end, gets released in a new version of the library. Optional parameters may break ABTs but since they're in new versions, recompilation is fair game. People should pin dependencies. |
addresses #186