1- using Microsoft . Extensions . Logging . Abstractions ;
2- using Newtonsoft . Json ;
1+ using Newtonsoft . Json ;
32using System . Buffers ;
43using System . Globalization ;
54using System . Text ;
@@ -22,30 +21,39 @@ internal class IpcJsonSerializer : ISerializer, IArrayPool<char>
2221#if ! NET461
2322 [ AsyncMethodBuilder ( typeof ( PoolingAsyncValueTaskMethodBuilder < > ) ) ]
2423#endif
25- public async ValueTask < T > DeserializeAsync < T > ( Stream json )
24+ public async ValueTask < T ? > DeserializeAsync < T > ( Stream json )
2625 {
2726 using var stream = IOHelpers . GetStream ( ( int ) json . Length ) ;
2827 await json . CopyToAsync ( stream ) ;
2928 stream . Position = 0 ;
3029 using var reader = CreateReader ( new StreamReader ( stream ) ) ;
3130 return StringArgsSerializer . Deserialize < T > ( reader ) ;
3231 }
33- public void Serialize ( object obj , Stream stream ) => Serialize ( obj , new StreamWriter ( stream ) , StringArgsSerializer ) ;
32+ public void Serialize ( object ? obj , Stream stream ) => Serialize ( obj , new StreamWriter ( stream ) , StringArgsSerializer ) ;
3433 private void Serialize ( object obj , TextWriter streamWriter , JsonSerializer serializer )
3534 {
3635 using var writer = new JsonTextWriter ( streamWriter ) { ArrayPool = this , CloseOutput = false } ;
3736 serializer . Serialize ( writer , obj ) ;
3837 writer . Flush ( ) ;
3938 }
4039 public char [ ] Rent ( int minimumLength ) => ArrayPool < char > . Shared . Rent ( minimumLength ) ;
41- public void Return ( char [ ] array ) => ArrayPool < char > . Shared . Return ( array ) ;
42- public string Serialize ( object obj )
40+ public void Return ( char [ ] ? array )
41+ {
42+ if ( array is null )
43+ {
44+ return ;
45+ }
46+
47+ ArrayPool < char > . Shared . Return ( array ) ;
48+ }
49+
50+ public string Serialize ( object ? obj )
4351 {
4452 var stringWriter = new StringWriter ( new StringBuilder ( capacity : 256 ) , CultureInfo . InvariantCulture ) ;
4553 Serialize ( obj , stringWriter , StringArgsSerializer ) ;
4654 return stringWriter . ToString ( ) ;
4755 }
48- public object Deserialize ( string json , Type type )
56+ public object ? Deserialize ( string json , Type type )
4957 {
5058 using var reader = CreateReader ( new StringReader ( json ) ) ;
5159 return StringArgsSerializer . Deserialize ( reader , type ) ;
0 commit comments