11using System ;
2+ using System . Linq ;
23using System . Threading . Tasks ;
34using Newtonsoft . Json ;
45using Npgsql . BackendMessages ;
@@ -12,7 +13,8 @@ public class JsonbHandlerFactory : NpgsqlTypeHandlerFactory<string>
1213 {
1314 readonly JsonSerializerSettings _settings ;
1415
15- public JsonbHandlerFactory ( JsonSerializerSettings settings ) => _settings = settings ;
16+ public JsonbHandlerFactory ( JsonSerializerSettings ? settings = null )
17+ => _settings = settings ?? new JsonSerializerSettings ( ) ;
1618
1719 protected override NpgsqlTypeHandler < string > Create ( NpgsqlConnection conn )
1820 => new JsonbHandler ( conn , _settings ) ;
@@ -24,7 +26,7 @@ class JsonbHandler : Npgsql.TypeHandlers.JsonbHandler
2426
2527 public JsonbHandler ( NpgsqlConnection connection , JsonSerializerSettings settings ) : base ( connection ) => _settings = settings ;
2628
27- protected override async ValueTask < T > Read < T > ( NpgsqlReadBuffer buf , int len , bool async , FieldDescription fieldDescription = null )
29+ protected override async ValueTask < T > Read < T > ( NpgsqlReadBuffer buf , int len , bool async , FieldDescription ? fieldDescription = null )
2830 {
2931 var s = await base . Read < string > ( buf , len , async, fieldDescription ) ;
3032 if ( typeof ( T ) == typeof ( string ) )
@@ -39,17 +41,17 @@ protected override async ValueTask<T> Read<T>(NpgsqlReadBuffer buf, int len, boo
3941 }
4042 }
4143
42- protected override int ValidateAndGetLength < T2 > ( T2 value , ref NpgsqlLengthCache lengthCache , NpgsqlParameter parameter )
44+ protected override int ValidateAndGetLength < T2 > ( T2 value , ref NpgsqlLengthCache ? lengthCache , NpgsqlParameter ? parameter )
4345 => typeof ( T2 ) == typeof ( string )
4446 ? base . ValidateAndGetLength ( value , ref lengthCache , parameter )
45- : ValidateObjectAndGetLength ( value , ref lengthCache , parameter ) ;
46-
47- protected override Task WriteWithLength < T2 > ( T2 value , NpgsqlWriteBuffer buf , NpgsqlLengthCache lengthCache , NpgsqlParameter parameter , bool async )
47+ : ValidateObjectAndGetLength ( value ! , ref lengthCache , parameter ) ;
48+
49+ protected override Task WriteWithLength < T2 > ( T2 value , NpgsqlWriteBuffer buf , NpgsqlLengthCache ? lengthCache , NpgsqlParameter ? parameter , bool async )
4850 => typeof ( T2 ) == typeof ( string )
4951 ? base . WriteWithLength ( value , buf , lengthCache , parameter , async)
50- : WriteObjectWithLength ( value , buf , lengthCache , parameter , async ) ;
52+ : WriteObjectWithLength ( value ! , buf , lengthCache , parameter , async) ;
5153
52- protected override int ValidateObjectAndGetLength ( object value , ref NpgsqlLengthCache lengthCache , NpgsqlParameter parameter )
54+ protected override int ValidateObjectAndGetLength ( object value , ref NpgsqlLengthCache ? lengthCache , NpgsqlParameter ? parameter )
5355 {
5456 var s = value as string ;
5557 if ( s == null )
@@ -61,10 +63,10 @@ protected override int ValidateObjectAndGetLength(object value, ref NpgsqlLength
6163 return base . ValidateObjectAndGetLength ( s , ref lengthCache , parameter ) ;
6264 }
6365
64- protected override Task WriteObjectWithLength ( object value , NpgsqlWriteBuffer buf , NpgsqlLengthCache lengthCache , NpgsqlParameter parameter , bool async )
66+ protected override Task WriteObjectWithLength ( object value , NpgsqlWriteBuffer buf , NpgsqlLengthCache ? lengthCache , NpgsqlParameter ? parameter , bool async )
6567 {
6668 if ( value == null || value is DBNull )
67- return base . WriteObjectWithLength ( value , buf , lengthCache , parameter , async) ;
69+ return base . WriteObjectWithLength ( DBNull . Value , buf , lengthCache , parameter , async) ;
6870
6971 if ( parameter ? . ConvertedValue != null )
7072 value = parameter . ConvertedValue ;
0 commit comments