-
Notifications
You must be signed in to change notification settings - Fork 43
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
JsonException path, position, error message etc. incorrect for records #37
Comments
Ah, this is bad indeed. It looks like the path is handled by passing a string to |
So, as it turns out, this is not currently possible. Even if I catch the exception and raise a new one with a correct path, the exception gets mutated by System.Text.Json and its path is reset to "$" based on some internal properties of the reader. There is a proposed API to make such things extensible, and it seems that they want to have it for .NET 5, but not before. |
Just to be clear, are you saying that with System.Text.Json it's not possible at all to get correct paths when implementing JSON converters for objects? (Except perhaps a hacky solution involving thread local storage or something, yuck...) |
As far as I can tell from reading the source of S.T.J, that's right. |
I have noticed that it's possible at least get the correct line number and byte position. In terms of the code in this repo, instead of calling
Instead, call (options.GetConverter(p.Type) :?> JsonConverter<??>).Read(&reader, p.Type, options) I'm not sure what you should place instead of When deserialization fails, you get a message like this:
The path is still incorrect, but the message is otherwise well formed, and the line number and byte position is correct and can be retrieved from the caught |
Actually, the |
dotnet/runtime#1562 seems to be implemented, any chance of looking into this again @Tarmil? |
FSharp.SystemTextJson completely messes up the path and error messages when deserialization fails.
This is causing me some consternation, because I am creating an F# framework for JSON:API (using an immutable record-based document model) and want to return helpful deserialization messages to API clients, but that's not currently possible.
Repro:
DeserializationErrorTest.zip
Expected outcome:
Actual outcome:
Expected outcome:
The text was updated successfully, but these errors were encountered: