-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
System.Text.Json: Add JsonReaderState.LineNumber and BytePositionInLine Property #50629
Comments
Tagging subscribers to this area: @eiriktsarpalis, @layomia Issue DetailsBackground and MotivationIn order to write a descent custom JSON (de)serializer, the
Proposed APInamespace System.Text.Json
{
public struct JsonReaderState
{
public long LineNumber => _lineNumber;
public long BytePositionInLine => _bytePositionInLine;
}
} Usage Examplesprivate static JsonException GetJsonExceptionToRethrow(string message, string path, JsonReaderState readerState, Exception ex)
{
return new JsonException(message, path, readerState.LineNumber, readerState.BytePositionInLine, ex);
} Alternative Designs
RisksDon't see any risk.
|
I agree this could be good information for custom serializers to provide, but would like to see more users ask for this before exposing API here (either on |
I have to write custom deserializer that skips some JSON fields with invalid data. Unfortunately I've to use reflection to show the position where the error occured. Voted for this feature. |
Duplicate of #28482 |
Background and Motivation
In order to write a descent custom JSON deserializer, the
LineNumber
andBytePositionInLine
, along withPath
information should be provided inJsonException
. The only way to getLineNumber
andBytePositionInLine
is throughJsonReaderState
struct. Unfortunately they're internal, which can only be consumed by the standard built-in deserializer.JsonException
has constructor to acceptLineNumber
andBytePositionInLine
parameter, but this information is not available unless using reflection.Proposed API
Usage Examples
Alternative Designs
JsonReaderState
is the only source of the information. Naturally this is the only way.Risks
Don't see any risk.
The text was updated successfully, but these errors were encountered: