Fix dictionary query request mapping #976
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Bug fix
What is the current behavior?
In the current version (5.2.1), dictionary query parameters with non-string keys throw an exception:
'Unable to cast object of type 'Example.Enum' to type 'System.String'.'
.Additionally, if the dictionary parameter is part of a complex object, the dictionary is serialized as
?DictionaryPropertyName=%5BKey%2C%20Value%5D
.This latter issue is reported here.
What is the new behavior?
The current query mapping code for IDictionary properties assumes that the dictionary key type is a string. This PR explicitly calls
ToString()
on the key before storing its value to the query map.For dictionaries that are a property on a complex query object, the current behavior treats them the same as ordinary collections (e.g., implements
IEnumerable<T>
). This PR implements the quick fix offered by @ThomasSmeets to skip this handling and be handled by the appropriate query map method.What might this PR break?
The change to handle IDictionary query parameters fixes an unhanded exception, this change is unlikely to break any existing assumptions.
The handling for IDictionary query properties that are part of a complex query objects may cause breaking changes for consumers who are expecting the previous serialization format (documented in this issue). However, prior to version 5.1.67, dictionary properties on query objects serialized as expected so this is likely a recent regression introduced by issue #896 and consumers are unlikely to be relying on this strange serialization behavior.
Please check if the PR fulfills these requirements