Start Debugging
2023-09-06 Actualizado 2023-11-05 csharpdotnetdotnet-8 Edit on GitHub

.NET 8 Memory<byte> se serializa como base64

A partir de .NET 8, tanto Memory<byte> como ReadOnlyMemory<byte> se serializan como cadenas Base64, mientras que otros tipos como Memory<int> siguen como arrays JSON.

A partir de .NET 8, tanto Memory<byte> como ReadOnlyMemory<byte> se serializan como cadenas Base64. Veamos un ejemplo rápido:

var bar = new byte[] { 28, 70, 0 };

JsonSerializer.Serialize<Memory<byte>>(bar);
JsonSerializer.Serialize<ReadOnlyMemory<byte>>(bar);
// Output: "HEYA"

En cambio, Memory<int> y similares seguirán serializándose como arrays JSON.

JsonSerializer.Serialize<Memory<int>>(new int[] { 28, 70, 0 });
// Output: [28,70,0]

Comments

Sign in with GitHub to comment. Reactions and replies thread back to the comments repo.

< Volver