You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Essentially, calling .Skip() in my custom JsonConverter<T> during a DeserializeAsync<T>(stream, ...) throws InvalidOperationException: Cannot skip tokens on partial JSON. Either get the whole payload and create a Utf8JsonReader instance where isFinalBlock is true or call TrySkip.
Calling TrySkip never returns false, though. So... why would Skip fail?
Anyway - this may be a case of me not knowing how to write a JsonConverter properly. However, apparently it doesn't occur in 3.1 and I was encouraged to open an issue. So here it is :D
The text was updated successfully, but these errors were encountered:
Looking through source, I see "Skip" is not even attempted if a non-final block is passed in. I was expecting the logic to be basically if (!TrySkip()) { throw new Explosion(); }. Looks like I was wrong.
In the existing JsonConverter model, custom converters do not have to worry about handling partial data, as the serializer passes all the data for the current JSON scope. Skip/TrySkip logic is unnecessary. cc @tdykstra we should consider adding a section about this in the docs.
The "read ahead" logic that the serializer performs to make this possible does have some perf implications. There has been some discussion around a new model to, among other benefits, enable more performant async-handling when custom converters are used - #1562. Relevant parts of the new model have been implemented internally in serializer, but exposing this publicly is not currently on the roadmap for System.Text.Json.
Details here: https://stackoverflow.com/questions/63038334/how-do-i-handle-partial-json-in-a-jsonconverter-while-using-deserializeasync-on
Essentially, calling
.Skip()
in my customJsonConverter<T>
during aDeserializeAsync<T>(stream, ...)
throwsInvalidOperationException: Cannot skip tokens on partial JSON. Either get the whole payload and create a Utf8JsonReader instance where isFinalBlock is true or call TrySkip.
Calling
TrySkip
never returns false, though. So... why wouldSkip
fail?Anyway - this may be a case of me not knowing how to write a JsonConverter properly. However, apparently it doesn't occur in 3.1 and I was encouraged to open an issue. So here it is :D
The text was updated successfully, but these errors were encountered: