11using System ;
2+ using System . IO ;
23using System . Text . Encodings . Web ;
34using System . Text . Json ;
45using System . Text . Json . Serialization ;
6+ using System . Threading . Tasks ;
57
68namespace DotNetCoreRpc . Core
79{
@@ -18,24 +20,29 @@ public static string ToJson<T>(this T data, JsonSerializerOptions options = defa
1820 return JsonSerializer . Serialize ( data , options ?? serializerOptions ) ;
1921 }
2022
21- public static T FromJson < T > ( this string json , JsonSerializerOptions options = default ) where T : class , new ( )
23+ public static byte [ ] ToUtf8Bytes < T > ( this T data , JsonSerializerOptions options = default ) where T : class , new ( )
2224 {
23- return JsonSerializer . Deserialize < T > ( json , options ?? serializerOptions ) ;
25+ return JsonSerializer . SerializeToUtf8Bytes ( data , options ?? serializerOptions ) ;
2426 }
2527
26- public static object FromJson ( this string json , Type type , JsonSerializerOptions options = default )
28+ public static Task WriteToStream < T > ( this T data , Stream utf8Json , JsonSerializerOptions options = default ) where T : class , new ( )
2729 {
28- return JsonSerializer . Deserialize ( json , type , options ?? serializerOptions ) ;
30+ return JsonSerializer . SerializeAsync ( utf8Json , data , options ?? serializerOptions ) ;
31+ }
32+
33+ public static T FromJson < T > ( this string json , JsonSerializerOptions options = default ) where T : class , new ( )
34+ {
35+ return JsonSerializer . Deserialize < T > ( json , options ?? serializerOptions ) ;
2936 }
3037
3138 public static T FromJson < T > ( this byte [ ] utf8Json , JsonSerializerOptions options = default ) where T : class , new ( )
3239 {
3340 return JsonSerializer . Deserialize < T > ( utf8Json , options ?? serializerOptions ) ;
3441 }
3542
36- public static object FromJson ( this byte [ ] utf8Json , Type type , JsonSerializerOptions options = default )
43+ public static ValueTask < T > FromStream < T > ( this Stream utf8Json , JsonSerializerOptions options = default ) where T : class , new ( )
3744 {
38- return JsonSerializer . Deserialize ( utf8Json , type , options ?? serializerOptions ) ;
45+ return JsonSerializer . DeserializeAsync < T > ( utf8Json , options ?? serializerOptions ) ;
3946 }
4047
4148 public static T FromJson < T > ( this JsonElement jsonElement , JsonSerializerOptions options = default ) where T : class , new ( )
0 commit comments