-
Notifications
You must be signed in to change notification settings - Fork 149
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
Suppress transmission of $type
property in named arguments objects
#651
Conversation
…n setting TypeNameHandling.Objects
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.
A surprisingly simple solution. Thanks for sharing.
However we lack two parts to the fix:
- We are sending invalid JSON-RPC requests still by transmitting
$type
as a property. We need to suppress that. - We need a regression test for this.
Are you interested in pursuing these items?
Andrew, sorry for delay, I was on vacation. I can look into your request. I did think about "filtering out" the type handling for the parameters dictionary while I was working on this solution. But I came across a few problems with that. I will look into it again and get back to you. First questions related to this topic,
|
Generally the goal is to control what the protocol dictates, and allow the app to do anything within that boundary. So in this case that means the named parameters object has one property for every parameter, and nothing more. But within each argument value, the app can do whatever it wants including having
You are probably correct about the test gap. And yes, I'm suggesting we need to fill that gap and then verify that the client never emits a |
$type
property in named arguments in incoming JSON requests
Codecov Report
@@ Coverage Diff @@
## main #651 +/- ##
==========================================
- Coverage 90.30% 90.22% -0.08%
==========================================
Files 59 59
Lines 4950 4952 +2
==========================================
- Hits 4470 4468 -2
- Misses 480 484 +4
Continue to review full report at Codecov.
|
…n setting TypeNameHandling.Objects
@AArnott, here is another attempt at the fix. It preserves compatibility with the Json RPC specification. I also added unit tests mostly by inheriting from some of the existing unit tests and re-executing them with TypeHandling set to "Objects". If you take the fix out you will notice that a lot of those unit tests fail. I ran the fix through our own unit tests which are heavily dependent on TypeHandling and it seems to work well. Please take a look. Also, I'm thinking it might be worth my time to add some true TypeHandling dependent unit tests were interfaces and sub-types are being serialized/deserialized. Thoughts? |
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.
Thank you for the fix to the product and tests.
I revised the product fix so we were less vulnerable to issues like this in the future, and to add a missing feature (declared types) that was lacking anyway.
$type
property in named arguments in incoming JSON requests$type
property in named arguments objects
Fix for issue #630: CancellationToken no longer works on v2.6.121 when setting TypeNameHandling.Objects.
When enabling TypeNameHandling.Objects for the JsonSerializer, invocations with simple object dictionaries would end with the dictionary's type in the "params".
With this type of message, the JsonMessageFormatter would convert the properties into a IReadOnlyDictionary<string, object>.
Unfortunately, this would treat the "type" JToken as a separate parameter which would then cause later failures because the number of parameters would be incorrect. The proposed solution is to first allow the JToken to convert itself to the right type of dictionary which uses and filters out the "type" and then convert it to the IReadOnlyDictionary<string, object>.
This solves all the issues discussed in #630.