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.
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
Samples for Newtonsoft migration doc #1837
Samples for Newtonsoft migration doc #1837
Changes from all commits
139f8bd
cef5c76
ff7158a
acd63d9
7c9d038
b39df9b
69059ee
37f1fc5
6e14136
b1c945b
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this is the right place for this, but this converter can be written more efficiently. So, maybe we suggest that?
reader.GetString()
for property name matching isn't necessary. You could useValueTextEquals
JsonEncodedText
is faster than comparison withstring
.if (!xSet || !ySet)
) by crafting the conditions differently.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we state why? cc @steveharter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have guidance against this? We do it internally: https://github.com/dotnet/runtime/blob/f77914d4c9045a01b3a91b63c28805f24850c274/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/JsonValueConverterKeyValuePair.cs#L127
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it would cause a stackoverflow in this case. I don't know if this is a bug or expected.
https://github.com/dotnet/runtime/blob/f77914d4c9045a01b3a91b63c28805f24850c274/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonPropertyInfoNotNullable.cs#L89
In the key value pair case, looks like we only call it for
object
and end up callingGetType
on it the next time, so it doesn't usually stackoverflow.But, this sample breaks that:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[EDIT] The bug here is caused by my mistake in adapting the KeyValueConverter code. I have corrected it now to call the int converter for each property instead of calling into Serialize(). So the advice to not pass in options doesn't apply in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The corrected code is here: https://github.com/dotnet/samples/blob/5dee66d52080f302775790bea4a25fe5afa938ac/snippets/core/system-text-json/csharp/ImmutablePointConverter.cs