Skip to content

Commit

Permalink
rename ToBytes to ToUtf8Bytes (dotnet/corefx#37912)
Browse files Browse the repository at this point in the history
Commit migrated from dotnet/corefx@4e342b9
  • Loading branch information
Anipik authored and stephentoub committed May 24, 2019
1 parent e89b9b2 commit 84aa86c
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/libraries/System.Text.Json/ref/System.Text.Json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ public static partial class JsonSerializer
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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static partial class JsonSerializer
/// <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);
}
Expand All @@ -24,7 +24,7 @@ public static byte[] ToBytes<TValue>(TValue value, JsonSerializerOptions 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static partial class JsonSerializer
/// <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)
Expand All @@ -29,7 +29,7 @@ public static string ToString<TValue>(TValue value, JsonSerializerOptions option
/// <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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ public static void NullObjectOutput()
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void WritePrimitives()
}

{
Span<byte> json = JsonSerializer.ToBytes(1);
Span<byte> json = JsonSerializer.ToUtf8Bytes(1);
Assert.Equal(Encoding.UTF8.GetBytes("1"), json.ToArray());
}

Expand All @@ -39,7 +39,7 @@ public static void WritePrimitives()
}

{
Span<byte> json = JsonSerializer.ToBytes(long.MaxValue);
Span<byte> json = JsonSerializer.ToUtf8Bytes(long.MaxValue);
Assert.Equal(Encoding.UTF8.GetBytes(long.MaxValue.ToString()), json.ToArray());
}

Expand All @@ -49,7 +49,7 @@ public static void WritePrimitives()
}

{
Span<byte> json = JsonSerializer.ToBytes("Hello");
Span<byte> json = JsonSerializer.ToUtf8Bytes("Hello");
Assert.Equal(Encoding.UTF8.GetBytes(@"""Hello"""), json.ToArray());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3504,7 +3504,7 @@ public void WriteDateTimeOffset_TrimsFractionCorrectly(string testStr, string ex
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)
Expand Down

0 comments on commit 84aa86c

Please sign in to comment.