Skip to content

Consider exposing path information as part of JsonReaderException #28960

@pranavkm

Description

@pranavkm

Runtime version: 3.0.0-preview4-27513-05

Consider:

public class Person
{
    public string Name { get; set; }
    public Address Address { get; set; }
}

public class Address
{
    public int ZipCode { get; set; }
}

var content = "{ \"Name\":  \"Test\", \"Address\": { \"ZipCode\": \"not-an-int\" } }";
var result = JsonSerializer.Parse(content, typeof(TestModel));

This throws an JsonReaderException, as expected:

Unhandled Exception: System.Text.Json.JsonReaderException: The JSON value from [test2.Person].Address.ZipCode could not be converted to System.Int32.

The exception includes the path as part of the error message, but there isn't a way to retrieve it as a property from the exception instance. It would be useful to additionally exposed the ath as a property along with the line and column information that JsonReaderException includes.

Metadata

Metadata

Assignees

Labels

api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-System.Text.JsonenhancementProduct code improvement that does NOT require public API changes/additions

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions