Fix Json deserializion of string containing hyphens to List<string> property #1094
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.
Issue
As discussed in #1026, there is an issue with the Json parser in a specific edge case.
When deserialising a
string
property into a class where that property is declared as aList<string>
(as is the case with the responses from the Enterprise SearchIndexing API), hyphens in the string are stripped during deserialization.Json
{ "message":"User \"ryan-gribble\" was added to the indexing queue" }
Class
public class MessageList { public IReadOnlyList<string> Message { get; private set; } }
Result
"User \"ryangribble\" was added to the indexing queue"
Expected Result
"User \"ryan-gribble\" was added to the indexing queue"
Resolution
This line (introduced in #727) was identified as responsible for the removal of the hyphens in the input string. Code inspection indicates the line appears to be unnecessary for the actual
Enum
andNullable Enum
cases mentioned when the change was made, as they already had code to remove hyphens in their if blocks.Unit tests were added to assert expected behaviour when deserializing a string attribute containing hyphens (and underscores for good measure) into
string
and<IReadOnlyList<string>
properties.After confirming the latter test failed, the offending line was removed and the tests then passed.
All other unit and integration tests were then also passed, indicating that no other known/tested functionality are impacted by the removal.