public static TValue Parse<TValue>(string json, System.Text.Json.Serialization.JsonSerializerOptions options = null) { throw null; }
public static System.Threading.Tasks.ValueTask<object> ReadAsync(System.IO.Stream utf8Json, System.Type returnType, System.Text.Json.Serialization.JsonSerializerOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static System.Threading.Tasks.ValueTask<TValue> ReadAsync<TValue>(System.IO.Stream utf8Json, System.Text.Json.Serialization.JsonSerializerOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
- public static byte[] ToBytes(object value, System.Type type, System.Text.Json.Serialization.JsonSerializerOptions options = null) { throw null; }
- public static byte[] ToBytes<TValue>(TValue value, System.Text.Json.Serialization.JsonSerializerOptions options = null) { throw null; }
+ public static byte[] ToUtf8Bytes(object value, System.Type type, System.Text.Json.Serialization.JsonSerializerOptions options = null) { throw null; }
+ public static byte[] ToUtf8Bytes<TValue>(TValue value, System.Text.Json.Serialization.JsonSerializerOptions options = null) { throw null; }
public static string ToString(object value, System.Type type, System.Text.Json.Serialization.JsonSerializerOptions options = null) { throw null; }
public static string ToString<TValue>(TValue value, System.Text.Json.Serialization.JsonSerializerOptions options = null) { throw null; }
public static System.Threading.Tasks.Task WriteAsync(object value, System.Type type, System.IO.Stream utf8Json, System.Text.Json.Serialization.JsonSerializerOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
/// <returns>A UTF-8 representation of the value.</returns>
/// <param name="value">The value to convert.</param>
/// <param name="options">Options to control the conversion behavior.</param>
- public static byte[] ToBytes<TValue>(TValue value, JsonSerializerOptions options = null)
+ public static byte[] ToUtf8Bytes<TValue>(TValue value, JsonSerializerOptions options = null)
{
return WriteCoreBytes(value, typeof(TValue), options);
}
/// <param name="value">The value to convert.</param>
/// <param name="type">The type of the <paramref name="value"/> to convert.</param>
/// <param name="options">Options to control the conversion behavior.</param>
- public static byte[] ToBytes(object value, Type type, JsonSerializerOptions options = null)
+ public static byte[] ToUtf8Bytes(object value, Type type, JsonSerializerOptions options = null)
{
VerifyValueAndType(value, type);
return WriteCoreBytes(value, type, options);
/// <param name="value">The value to convert.</param>
/// <param name="options">Options to control the conversion behavior.</param>
/// <remarks>Using a <see cref="System.String"/> is not as efficient as using UTF-8
- /// encoding since the implementation internally uses UTF-8. See also <see cref="ToBytes"/>
+ /// encoding since the implementation internally uses UTF-8. See also <see cref="ToUtf8Bytes"/>
/// and <see cref="WriteAsync"/>.
/// </remarks>
public static string ToString<TValue>(TValue value, JsonSerializerOptions options = null)
/// <param name="type">The type of the <paramref name="value"/> to convert.</param>
/// <param name="options">Options to control the conversion behavior.</param>
/// <remarks>Using a <see cref="System.String"/> is not as efficient as using UTF-8
- /// encoding since the implementation internally uses UTF-8. See also <see cref="ToBytes"/>
+ /// encoding since the implementation internally uses UTF-8. See also <see cref="ToUtf8Bytes"/>
/// and <see cref="WriteAsync"/>.
/// </remarks>
public static string ToString(object value, Type type, JsonSerializerOptions options = null)
byte[] encodedNull = Encoding.UTF8.GetBytes(@"null");
{
- byte[] output = JsonSerializer.ToBytes(null, null);
+ byte[] output = JsonSerializer.ToUtf8Bytes(null, null);
Assert.Equal(encodedNull, output);
}
{
- byte[] output = JsonSerializer.ToBytes(null, typeof(NullTests));
+ byte[] output = JsonSerializer.ToUtf8Bytes(null, typeof(NullTests));
Assert.Equal(encodedNull, output);
}
}
}
{
- Span<byte> json = JsonSerializer.ToBytes(1);
+ Span<byte> json = JsonSerializer.ToUtf8Bytes(1);
Assert.Equal(Encoding.UTF8.GetBytes("1"), json.ToArray());
}
}
{
- Span<byte> json = JsonSerializer.ToBytes(long.MaxValue);
+ Span<byte> json = JsonSerializer.ToUtf8Bytes(long.MaxValue);
Assert.Equal(Encoding.UTF8.GetBytes(long.MaxValue.ToString()), json.ToArray());
}
}
{
- Span<byte> json = JsonSerializer.ToBytes("Hello");
+ Span<byte> json = JsonSerializer.ToUtf8Bytes("Hello");
Assert.Equal(Encoding.UTF8.GetBytes(@"""Hello"""), json.ToArray());
}
}
public void WriteDateTime_TrimsFractionCorrectly_SerializerRoundtrip()
{
DateTime utcNow = DateTime.UtcNow;
- Assert.Equal(utcNow, Serialization.JsonSerializer.Parse(Serialization.JsonSerializer.ToBytes(utcNow), typeof(DateTime)));
+ Assert.Equal(utcNow, Serialization.JsonSerializer.Parse(Serialization.JsonSerializer.ToUtf8Bytes(utcNow), typeof(DateTime)));
}
private static void WriteTooLargeHelper(JsonWriterOptions options, ReadOnlySpan<byte> key, ReadOnlySpan<byte> value, bool noThrow = false)