Search SDK: Fixing DateTime deserialization and time zone-specific un… #1378
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.
…it tests
NOTE: I am not incrementing the NuGet package version because there is
another PR coming very soon and there's no point in shipping a new SDK
version that will only live for one day.
Apparently deserialization of DateTime in Search results has been broken
since the Search SDK first shipped (DateTimeOffset deserialization works
fine). The root cause is the "double deserialization" we need to do in order
to "unflatten" the search response JSON. First we deserialize to JObject and
capture the OData annotations (for things like @search.highlight,
@search.score, etc.). This results in the DateTime fields being deserialized
into DateTimeOffsets. Next, we deserialize again into the user's model class,
which was resulting in an InvalidCastException because JSON.NET can't cast
DateTimeOffset to DateTime. The fix is to add some read logic to
DateTimeConverter (and a lot of new test coverage).
I also took the opportunity to fix some unit tests that weren't running
correctly in other time zones. This bug was reported back in June:
#1202