Skip to content

Use explicit subconverters for [NodaTimeDefaultJsonConverter] for Interval and DateInterval #136

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jskeet
Copy link
Member

@jskeet jskeet commented Feb 15, 2025

Fixes #135

@jskeet
Copy link
Member Author

jskeet commented Feb 15, 2025

cc @kaydensigh to check whether this looks right to you

Copy link
Collaborator

@malcolmr malcolmr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/nodatime/nodatime.serialization/blob/e1f2cf4/src/NodaTime.Serialization.SystemTextJson/NodaConverters.cs#L52 also has a This must be used in a serializer which also has an instant converter. comment - is that still true after this change?

@@ -40,7 +40,7 @@ private static Dictionary<Type, JsonConverter> CreateConverterDictionary()
Add(NodaConverters.AnnualDateConverter);
Add(NodaConverters.DurationConverterImpl);
Add(NodaConverters.InstantConverter);
Add(NodaConverters.IntervalConverter);
Add(new NodaIntervalConverter(NodaConverters.InstantConverter));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must admit that I'm not entirely following this change, but should this change be made to the NodaConverters.IntervalConverter property itself?

(That would also obviate the need for two separate constructors for NodaIntervalConverter etc, I think.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so - because if someone creates a set of options and specifies a non-default Instant converter (e.g. new NodaJsonSettings { IntervalConverter = ...}, that should be used for converting the instants in an interval, IMO.

/// <summary>
/// Instant converter to use, overriding whatever is in JsonSerializerOptions.
/// </summary>
private readonly JsonConverter<Instant> instantConverter;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I'm surprised this doesn't need to be declared as nullable; but also later I'm also asking if we need to accept null here.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not using nullable reference types in this project yet. (I should probably do so at some point.)

@jskeet
Copy link
Member Author

jskeet commented Feb 15, 2025

https://github.com/nodatime/nodatime.serialization/blob/e1f2cf4/src/NodaTime.Serialization.SystemTextJson/NodaConverters.cs#L52 also has a This must be used in a serializer which also has an instant converter. comment - is that still true after this change?

Yes, for the interval converter returned by that property. (Whereas now you can construct an interval converter that always uses a specific one.)

@kaydensigh
Copy link

cc @kaydensigh to check whether this looks right to you

Yup. As a user, having NodaTimeDefaultJsonConverter behave predictably on Instant and Interval is perfect. Thanks a lot!

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.

NodaTimeDefaultJsonConverter doesn't seem to work with Interval
3 participants