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

JsonValueReaderWriter.FromJsonString doesn't seem to correctly parse #32269

Closed
roji opened this issue Nov 9, 2023 · 0 comments · Fixed by #32393
Closed

JsonValueReaderWriter.FromJsonString doesn't seem to correctly parse #32269

roji opened this issue Nov 9, 2023 · 0 comments · Fixed by #32393
Labels
area-json closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@roji
Copy link
Member

roji commented Nov 9, 2023

var readerWriter2 = JsonInt32ReaderWriter.Instance;

var i = readerWriter2.ToJsonString(8); // i is "8"
var j = (int)readerWriter2.FromJsonString(i);

Stack trace:

Cannot get the value of a token type 'None' as a number.
   at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_ExpectedNumber(JsonTokenType tokenType)
   at System.Text.Json.Utf8JsonReader.TryGetInt32(Int32& value)
   at System.Text.Json.Utf8JsonReader.GetInt32()
   at Microsoft.EntityFrameworkCore.Storage.Json.JsonInt32ReaderWriter.FromJsonTyped(Utf8JsonReaderManager& manager, Object existingObject) in /home/roji/projects/efcore/src/EFCore/Storage/Json/JsonInt32ReaderWriter.cs:line 24

The problem seems to be that ToJsonString() doesn't read the first tokenbefore calling into FromJson().

FromJsonString() is used in CollectionToJsonStringConverter (and only there), that may be broken as a result.

/cc @ajcvickers

@ajcvickers ajcvickers self-assigned this Nov 15, 2023
@ajcvickers ajcvickers added this to the 9.0.0 milestone Nov 17, 2023
ajcvickers added a commit that referenced this issue Nov 22, 2023
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Nov 22, 2023
@ajcvickers ajcvickers modified the milestones: 9.0.0, 9.0.0-preview1 Jan 31, 2024
@ajcvickers ajcvickers removed their assignment Aug 31, 2024
@roji roji modified the milestones: 9.0.0-preview1, 9.0.0 Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-json closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants