Skip to content

Feature request: treat Memory/ReadOnlyMemory<T> as T[] in System.Text.Json #86442

Closed
@sandersaares

Description

@sandersaares

EDIT: see #86442 (comment) for API proposal.

Original Proposal

I would like System.Text.Json to serialize/deserialize Memory/ReadOnlyMemory<T> using the same logic as it uses for T[].

This implies:

  • Memory<byte> should be base64-encoded just like byte[] is
  • Memory<FooBar> should be serialized as appropriate for the type FooBar, same as FooBar[] would.

The main motivation is that I have an array from ArrayPool<T>.Shared, which can have space for more items than I actually need. To serialize only a segment of the array, I would like to use Memory<T> to identify only use "used" part of the array.

Metadata

Metadata

Labels

api-approvedAPI was approved in API review, it can be implementedarea-System.Text.Jsonpartner-impactThis issue impacts a partner who needs to be kept updated

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions