Skip to content

Commit

Permalink
Correctly parse JSON from string (#32393)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers authored Nov 23, 2023
1 parent 84505e3 commit c5262bb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
5 changes: 0 additions & 5 deletions src/EFCore/Storage/Json/JsonCollectionReaderWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ public JsonCollectionReaderWriter(JsonValueReaderWriter<TElement> elementReaderW
collection.Clear();
}

if (manager.CurrentReader.TokenType == JsonTokenType.None)
{
manager.MoveNext();
}

var tokenType = manager.CurrentReader.TokenType;
if (tokenType != JsonTokenType.StartArray)
{
Expand Down
1 change: 1 addition & 0 deletions src/EFCore/Storage/Json/JsonValueReaderWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ internal JsonValueReaderWriter()
public object FromJsonString(string json, object? existingObject = null)
{
var readerManager = new Utf8JsonReaderManager(new JsonReaderData(Encoding.UTF8.GetBytes(json)), null);
readerManager.MoveNext();
return FromJson(ref readerManager, existingObject);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\EFCore\EFCore.csproj" />
<ProjectReference Include="..\..\src\EFCore.Analyzers\EFCore.Analyzers.csproj" />
<ProjectReference Include="..\..\src\EFCore.Design\EFCore.Design.csproj" />
<ProjectReference Include="..\..\src\EFCore.Proxies\EFCore.Proxies.csproj" />
<ProjectReference Include="..\..\src\EFCore.Abstractions\EFCore.Abstractions.csproj" />
Expand Down
9 changes: 8 additions & 1 deletion test/EFCore.Specification.Tests/JsonTypesTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3505,6 +3505,10 @@ protected virtual void Can_read_and_write_JSON_value<TEntity, TModel>(
var jsonReaderWriter = property.GetJsonValueReaderWriter()
?? property.GetTypeMapping().JsonValueReaderWriter!;

var toString = value == null ? null : jsonReaderWriter.ToJsonString(value);
var fromString = toString == null ? null : jsonReaderWriter.FromJsonString(toString, existingObject);
Assert.Equal(value, fromString);

var actual = ToJsonPropertyString(jsonReaderWriter, value);
Assert.Equal(json, actual);

Expand Down Expand Up @@ -3782,7 +3786,10 @@ public override Geometry FromJsonTyped(ref Utf8JsonReaderManager manager, object
throw new ArgumentOutOfRangeException();
}

manager.MoveNext();
if (depth > 0)
{
manager.MoveNext();
}
}
while (depth > 0);

Expand Down

0 comments on commit c5262bb

Please sign in to comment.