Skip to content

Position information lost when calling JsonSerializer.Deserialize overloads accepting Utf8JsonReader. #97893

Description

@gregsdennis

Description

It seems that when attempting to deserialize a type that's nested within another, and there's a failure (e.g. wrong JSON type) on the nested data, the reported position information is incorrect.

Reproduction Steps

Repro: ConsoleApp1.zip

It might not be minimal, but it's pretty small.

Expected behavior

The position in the JSON source should be reported correctly.

Actual behavior

The position in the JSON source is not reported correctly.

Regression?

I'm not sure if this is a regression for source gen, but it definitely works without source gen.

Known Workarounds

We've created a number of JsonSerializerOptions extension methods in Json.More to mitigate this for now, but it's a less desired approach.

Configuration

Libraries multitargeting .Net Standard 2.0 & .Net 8
Tests running in .Net 6 and .Net 8 (fails in both)

Repro is just .Net 8

Other information

Some offline context from @eiriktsarpalis:

JsonSerializer.Deserialize methods acceping a Ut8fJsonReader. The methods need to create a new Utf8JsonReader that is scoped to the particular JSON value you are trying to deserialize, which in the process loses information on the data that has been read so far.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions