rename ToBytes to ToUtf8Bytes (dotnet/corefx#37912)
authorAnirudh Agnihotry <anirudhagnihotry098@gmail.com>
Fri, 24 May 2019 15:50:13 +0000 (08:50 -0700)
committerStephen Toub <stoub@microsoft.com>
Fri, 24 May 2019 15:50:12 +0000 (11:50 -0400)
Commit migrated from https://github.com/dotnet/corefx/commit/4e342b94a06e21604cd805d0340ef871adc47c43

src/libraries/System.Text.Json/ref/System.Text.Json.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.ByteArray.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.String.cs
src/libraries/System.Text.Json/tests/Serialization/SpanTests.cs
src/libraries/System.Text.Json/tests/Serialization/Value.WriteTests.cs
src/libraries/System.Text.Json/tests/Utf8JsonWriterTests.cs

index 935efd7..fd42e29 100644 (file)
@@ -382,8 +382,8 @@ namespace System.Text.Json.Serialization
         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; }
index 595bac8..7769842 100644 (file)
@@ -12,7 +12,7 @@ namespace System.Text.Json.Serialization
         /// <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);
         }
@@ -24,7 +24,7 @@ namespace System.Text.Json.Serialization
         /// <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);
index 48c53aa..3a408a8 100644 (file)
@@ -13,7 +13,7 @@ namespace System.Text.Json.Serialization
         /// <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)
@@ -29,7 +29,7 @@ namespace System.Text.Json.Serialization
         /// <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)
index b8ef567..2dd50b7 100644 (file)
@@ -60,12 +60,12 @@ namespace System.Text.Json.Serialization.Tests
             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);
             }
         }
index 55f0643..eb557eb 100644 (file)
@@ -29,7 +29,7 @@ namespace System.Text.Json.Serialization.Tests
             }
 
             {
-                Span<byte> json = JsonSerializer.ToBytes(1);
+                Span<byte> json = JsonSerializer.ToUtf8Bytes(1);
                 Assert.Equal(Encoding.UTF8.GetBytes("1"), json.ToArray());
             }
 
@@ -39,7 +39,7 @@ namespace System.Text.Json.Serialization.Tests
             }
 
             {
-                Span<byte> json = JsonSerializer.ToBytes(long.MaxValue);
+                Span<byte> json = JsonSerializer.ToUtf8Bytes(long.MaxValue);
                 Assert.Equal(Encoding.UTF8.GetBytes(long.MaxValue.ToString()), json.ToArray());
             }
 
@@ -49,7 +49,7 @@ namespace System.Text.Json.Serialization.Tests
             }
 
             {
-                Span<byte> json = JsonSerializer.ToBytes("Hello");
+                Span<byte> json = JsonSerializer.ToUtf8Bytes("Hello");
                 Assert.Equal(Encoding.UTF8.GetBytes(@"""Hello"""), json.ToArray());
             }
         }
index 34f97e9..7eb66b6 100644 (file)
@@ -3504,7 +3504,7 @@ namespace System.Text.Json.Tests
         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)