[API Proposal]: Add JsonSerializer.Deserialize(ReadOnlySequence) #100478
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-System.Text.Json
untriaged
New issue has not been triaged by the area owner
Background and motivation
In #68586
DeserializeAsync(PipeReader)
is proposed, but there are dependency issues because theSystem.IO.Pipelines
package is not included in the framework.If
Deserialize(ReadOnlySequence<byte>)
is supported, it would be very easy to write code like follows.There is no dependency problem because the
ReadOnlySequence<T>
is a type included in the framework and already depended on byUtf8JsonReader
and so on.API Proposal
API Usage
Alternative Designs
The objective may be achieved by combining the following already provided functions.
But to me, the correct way to implement these is not always intuitive.
or
If these are recommended, please provide documentation for them.
Also, please provide methods to retrieve
JsonReaderOptions
andJsonDocumentOptions
fromJsonSerializerOptions
.JsonSerializerOptions.GetReaderOptions
andJsonSerializerOptions.GetDocumentOptions
are currentlyinternal
, so please consider making thempublic
.The
JsonSerializer.Deserialize
is a method that already has numerous overloads.There are two ways to return: one that returns a strongly typed object and one that returns
object
.There are also three variations to provide deserialization options.
JsonSerializerOptions
JsonSerializerContext
JsonTypeInfo
(including its generic version)The proposal would add
ReadOnlySequence<char>
andReadOnlySequence<byte>
as the first parameter type for each of the six patterns consisting of these combinations, increasing the total number of overloads by 12.This is an excessive increase, and I would be ok with only some of these being implemented.
If the importance is to work with
PipeReader
, then at a minimum, only the following two would be needed.To extend while limiting the combinatorial explosion due to overloading, it might be conceivable to provide a new style of API, such as the following.
If
JsonSerializer
were not a static class, it would be easy to provide these variations through extension methods.Extensions to static classes will have to wait for extensions to be implemented.
Risks
At #68586 (comment), it is noted that there is a reliability issue.
The text was updated successfully, but these errors were encountered: