Skip to content

[API Proposal]: JsonSerializer.TryReadValue(ref Utf8JsonReader) #29902

@davidfowl

Description

@davidfowl

Today if the JSON passed into the JsonSerializer needs to be the fully formed, this means its basically impossible to let the caller handle buffering (which is unfortunate). This seems solvable if we add a TryReadValue which would return false if the Serializer failed to Read the full object from the Utf8JsonReader.

public static class JsonSerializer
{
    public static bool TryReadValue(ref Utf8JsonReader reader, Type returnType, out object value, JsonSerializerOptions options = null);
    public static bool TryReadValue<TValue>(ref Utf8JsonReader reader, out TValue value, JsonSerializerOptions options = null);
}

This currently wouldn't preserve the serializer state, but it would let the caller buffer an entire JSON payload from a Stream of bytes without a surrounding envelope.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-System.Text.Jsonbacklog-cleanup-candidateAn inactive issue that has been marked for automated closure.needs-further-triageIssue has been initially triaged, but needs deeper consideration or reconsideration

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions