Skip to content

Conversation

@Maximys
Copy link
Contributor

@Maximys Maximys commented Nov 1, 2025

This PR fixes #113926 as recommended by @eiriktsarpalis here.

Really, I'm not sure, that current implementation is simpler than first one. Maybe I don't understand something about generics, but from my point of view it is really impossible to fix the current error in the simpler way proposed

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Nov 1, 2025
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@huoyaoyuan huoyaoyuan left a comment

Choose a reason for hiding this comment

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

This PR is repeating the mistakes from #114863. You can follow #114863 (review) literally, and the code should be simpler than final state of #114863. The PR was mostly working and you should start from it.


namespace System.Text.Json.Extensions
{
internal static class Utf8JsonReaderExtensions
Copy link
Member

Choose a reason for hiding this comment

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

As mentioned in #114863 (comment), the read/write methods must not be directly called by JsonValue converters. They must resolve and call any registered JsonConverter<TPrimitive>.

/// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
/// <param name="options">Options to control the behavior.</param>
/// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
internal static JsonValue Create(DateOnly value, JsonNodeOptions? options = null) => new JsonValuePrimitive<DateOnly>(value, JsonMetadataServices.DateOnlyConverter, options);
Copy link
Member

Choose a reason for hiding this comment

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

It is incorrect to use any JsonMetadataServices.XXConverter either. The converter from JsonSerializationOptions should be used.


namespace System.Text.Json.Serialization.Metadata
{
internal sealed class SimpleConverterTypeComparer : IEqualityComparer<Type>
Copy link
Member

Choose a reason for hiding this comment

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

What is this at all? Type can just be compared by reference when used in dictionary.

@Maximys
Copy link
Contributor Author

Maximys commented Nov 1, 2025

Really, I'm not sure, that current implementation is simpler than first one. Maybe I don't understand something about generics, but from my point of view it is really impossible to fix the current error in the simpler way proposed

As I wrote in root message of current PR, I understand that current changes is more difficult than in PR #114863 , but it's impossible to make it simplier by adding JsonValueConverter<JsonValuePrimitive> to list of converters, because JsonValuePrimitive is generic!

@huoyaoyuan
Copy link
Member

but it's impossible to make it simplier by adding JsonValueConverter<JsonValuePrimitive> to list of converters, because JsonValuePrimitive is generic!

Non-generic JsonValueConverter can already create generic JsonValue<T> with a dispatch method JsonValue.CreateFromElement. Though I'm not 100% understanding the comment, I'm sure that you just need a variation of JsonValueConverter that returns the correct type.

Anyway, this PR is not going to work. The primitive value converters should not be touched nor directly used.

@eiriktsarpalis eiriktsarpalis added the needs-author-action An issue or pull request that requires more info or actions from the author. label Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Text.Json community-contribution Indicates that the PR has been added by a community member needs-author-action An issue or pull request that requires more info or actions from the author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deserialization of a JsonNode with string value fails

3 participants