Skip to content
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

Fixed DateTime serialization with JSON using single quotes #768

Merged
merged 2 commits into from Jan 15, 2023

Conversation

EdwardCooke
Copy link
Collaborator

@EdwardCooke EdwardCooke commented Jan 15, 2023

Fixes #587

When using JsonCompatible we will now register a DateTimeConverter.

If the user is adding a DateTimeConverter object before calling JsonCompatible on the serializer, this call will fail. If the user is adding some other, custom, DateTime converter, the one added by JsonCompatible will take priority, and the users converter will be skipped.

If the user wants to specify their own DateTimeConverter or some other DateTime converter object, they will need to do it after calling JsonCompatible.

If they are passing their own DateTimeConverter, they can now specify the optional constructor argument, doubleQuotes, so it will dish out valid JSON.

@EdwardCooke EdwardCooke force-pushed the ec-fix-587 branch 2 times, most recently from 679ac8a to 90bbef3 Compare January 15, 2023 05:00
@EdwardCooke EdwardCooke merged commit 306f714 into aaubry:master Jan 15, 2023
@stan-sz
Copy link
Contributor

stan-sz commented Jan 20, 2023

@EdwardCooke - my local test runs fail with

[xUnit.net 00:00:02.63]     JsonCompatible_EncaseDateTimesInDoubleQuotes [FAIL]
  Failed JsonCompatible_EncaseDateTimesInDoubleQuotes [7 ms]
  Error Message:
   Expected string to contain equivalent of "{\"DateTime\": \"01/14/2023 00:01:02\"}" but found "{\"DateTime\": \"01/13/2023 23:01:02\"}"

My guess is that the constructor in the test case is missing the DateTimeKind as:

var testObject = new TestObject { DateTime = new DateTime(2023, 01, 14, 0, 1, 2, DateTimeKind.Utc) };

@EdwardCooke
Copy link
Collaborator Author

This flaky test will be fixed in the next release.

@EdwardCooke EdwardCooke deleted the ec-fix-587 branch August 14, 2023 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DateTime JSON compatible serialization doesn't put the date string in double quotes
2 participants