Skip to content

Ensure JsonConverter<T>.Read/WriteAsPropertyName methods are user-callable.#77488

Merged
eiriktsarpalis merged 1 commit intodotnet:mainfrom
eiriktsarpalis:fix-jsonconverter-writeaspropertyname
Oct 28, 2022
Merged

Ensure JsonConverter<T>.Read/WriteAsPropertyName methods are user-callable.#77488
eiriktsarpalis merged 1 commit intodotnet:mainfrom
eiriktsarpalis:fix-jsonconverter-writeaspropertyname

Conversation

@eiriktsarpalis
Copy link
Member

Also adds property name serialization for TimeSpan, TimeOnly, DateOnly, Uri and Version built-in converters.

Fix #77326

…lable.

Also adds property name serialization for TimeSpan, TimeOnly, DateOnly, Uri and Version built-in converters.

Fix dotnet#77326
@ghost
Copy link

ghost commented Oct 26, 2022

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

Issue Details

Also adds property name serialization for TimeSpan, TimeOnly, DateOnly, Uri and Version built-in converters.

Fix #77326

Author: eiriktsarpalis
Assignees: -
Labels:

area-System.Text.Json

Milestone: -

@eiriktsarpalis eiriktsarpalis added this to the 8.0.0 milestone Oct 26, 2022
{
await Assert.ThrowsAsync<NotSupportedException>(async () => await Serializer.DeserializeWrapper<IReadOnlyDictionary<Uri, int>>(@"{""http://foo"":1}"));
await Assert.ThrowsAsync<NotSupportedException>(async () => await Serializer.SerializeWrapper(new GenericIReadOnlyDictionaryWrapper<Uri, int>(new Dictionary<Uri, int> { { new Uri("http://foo"), 1 } })));
await Assert.ThrowsAsync<NotSupportedException>(async () => await Serializer.DeserializeWrapper<IReadOnlyDictionary<JsonNode, int>>(@"{""key"":1}"));
Copy link
Member

Choose a reason for hiding this comment

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

what changed with regard to Uris?

Copy link
Member Author

Choose a reason for hiding this comment

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

They now support property name serialization.


internal override Uri ReadAsPropertyNameCore(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
Debug.Assert(reader.TokenType is JsonTokenType.PropertyName);
Copy link
Member

Choose a reason for hiding this comment

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

was this throwing before?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, Uri key serialization was not supported.

@eiriktsarpalis eiriktsarpalis requested a review from krwq October 27, 2022 10:07
Copy link
Contributor

@layomia layomia left a comment

Choose a reason for hiding this comment

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

LGTM.

@eiriktsarpalis eiriktsarpalis merged commit 8c496e7 into dotnet:main Oct 28, 2022
@eiriktsarpalis eiriktsarpalis deleted the fix-jsonconverter-writeaspropertyname branch October 28, 2022 10:12
@ghost ghost locked as resolved and limited conversation to collaborators Nov 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

3 participants