@@ -5,20 +5,11 @@ namespace DotNet.Extensions;
55
66public static class ObjectExtensions
77{
8- static readonly Lazy < JsonSerializerOptions > s_lazyOptions = new ( ( ) => new ( )
9- {
10- Converters = { new JsonStringEnumConverter ( JsonNamingPolicy . CamelCase ) } ,
11- Encoder = JavaScriptEncoder . UnsafeRelaxedJsonEscaping ,
12- NumberHandling = JsonNumberHandling . AllowReadingFromString | JsonNumberHandling . WriteAsString ,
13- PropertyNameCaseInsensitive = true ,
14- AllowTrailingCommas = true ,
15- } ) ;
8+ public static string ? ToJson < T > ( this T value , JsonTypeInfo < T > jsonTypeInfo ) =>
9+ value is null ? null : Serialize ( value , jsonTypeInfo ) ;
1610
17- public static string ? ToJson ( this object value , JsonSerializerOptions ? options = default ) =>
18- value is null ? null : Serialize ( value , options ?? s_lazyOptions . Value ) ;
19-
20- public static T ? FromJson < T > ( this string ? json , JsonSerializerOptions ? options = default ) =>
21- string . IsNullOrWhiteSpace ( json ) ? default : Deserialize < T > ( json , options ?? s_lazyOptions . Value ) ;
11+ public static T ? FromJson < T > ( this string ? json , JsonTypeInfo < T > jsonTypeInfo ) =>
12+ string . IsNullOrWhiteSpace ( json ) ? default : Deserialize < T > ( json , jsonTypeInfo ) ;
2213
2314 public static DateTime ? ToDateTime ( this string ? value ) =>
2415 value is null ? default : DateTime . TryParse ( value , out global ::System . DateTime dateTime ) ? dateTime : null ;
0 commit comments