Skip to content

[API Proposal]: ReadOnlySequence<byte> handling by System.Text.Json source generator #95187

@paulomorgado

Description

@paulomorgado

Background and motivation

In .NET 8.0, System.Text.Json source generator generates code to JSON serialize ReadOnlyMemory<byte> values the same way as byte[].

To avoid extra allocations, it would be nice to be able to JSON serialize ReadOnlySequence<byte> the same way.

Currently, the generator tries to write code to serialize ReadOnlySequence<byte>, which is not possible.

API Proposal

// System.Text.Json source generator code
// ...

API Usage

public class Dto
{
    public ReadOnlySequence<byte> Data { get; set; }
}

[JsonSerializable(typeof(Dto))]
public partial class Class1JsonSerializationContext : JsonSerializerContext
{
}

Alternative Designs

No response

Risks

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions