@@ -13,39 +13,39 @@ public static class JsonExtensions
1313 ReferenceHandler = ReferenceHandler . IgnoreCycles
1414 } ;
1515
16- public static string ToJson < T > ( this T data ) where T : class , new ( )
16+ public static string ToJson < T > ( this T data , JsonSerializerOptions options = default ) where T : class , new ( )
1717 {
18- return JsonSerializer . Serialize ( data , serializerOptions ) ;
18+ return JsonSerializer . Serialize ( data , options ?? serializerOptions ) ;
1919 }
2020
21- public static T FromJson < T > ( this string json ) where T : class , new ( )
21+ public static T FromJson < T > ( this string json , JsonSerializerOptions options = default ) where T : class , new ( )
2222 {
23- return JsonSerializer . Deserialize < T > ( json , serializerOptions ) ;
23+ return JsonSerializer . Deserialize < T > ( json , options ?? serializerOptions ) ;
2424 }
2525
26- public static object FromJson ( this string json , Type type )
26+ public static object FromJson ( this string json , Type type , JsonSerializerOptions options = default )
2727 {
28- return JsonSerializer . Deserialize ( json , type , serializerOptions ) ;
28+ return JsonSerializer . Deserialize ( json , type , options ?? serializerOptions ) ;
2929 }
3030
31- public static T FromJson < T > ( this byte [ ] utf8Json ) where T : class , new ( )
31+ public static T FromJson < T > ( this byte [ ] utf8Json , JsonSerializerOptions options = default ) where T : class , new ( )
3232 {
33- return JsonSerializer . Deserialize < T > ( utf8Json , serializerOptions ) ;
33+ return JsonSerializer . Deserialize < T > ( utf8Json , options ?? serializerOptions ) ;
3434 }
3535
36- public static object FromJson ( this byte [ ] utf8Json , Type type )
36+ public static object FromJson ( this byte [ ] utf8Json , Type type , JsonSerializerOptions options = default )
3737 {
38- return JsonSerializer . Deserialize ( utf8Json , type , serializerOptions ) ;
38+ return JsonSerializer . Deserialize ( utf8Json , type , options ?? serializerOptions ) ;
3939 }
4040
41- public static T FromJson < T > ( this JsonElement jsonElement ) where T : class , new ( )
41+ public static T FromJson < T > ( this JsonElement jsonElement , JsonSerializerOptions options = default ) where T : class , new ( )
4242 {
43- return jsonElement . Deserialize < T > ( serializerOptions ) ;
43+ return jsonElement . Deserialize < T > ( options ?? serializerOptions ) ;
4444 }
4545
46- public static object FromJson ( this JsonElement jsonElement , Type type )
46+ public static object FromJson ( this JsonElement jsonElement , Type type , JsonSerializerOptions options = default )
4747 {
48- return jsonElement . Deserialize ( type , serializerOptions ) ;
48+ return jsonElement . Deserialize ( type , options ?? serializerOptions ) ;
4949 }
5050 }
5151}
0 commit comments