Skip to content

Commit 4e7162c

Browse files
committed
JSON.NET handlers correcty handle null and DBNull values
1 parent 4d00a31 commit 4e7162c

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

src/Npgsql.Json.NET/JsonHandler.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ protected override int ValidateObjectAndGetLength(object value, ref NpgsqlLength
8686

8787
protected override Task WriteObjectWithLength(object value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
8888
{
89+
if (value == null || value is DBNull)
90+
return base.WriteObjectWithLength(value, buf, lengthCache, parameter, async);
91+
8992
if (parameter?.ConvertedValue != null)
9093
value = parameter.ConvertedValue;
9194
var s = value as string ?? JsonConvert.SerializeObject(value, _settings);

src/Npgsql.Json.NET/JsonbHandler.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ protected override int ValidateObjectAndGetLength(object value, ref NpgsqlLength
8686

8787
protected override Task WriteObjectWithLength(object value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
8888
{
89+
if (value == null || value is DBNull)
90+
return base.WriteObjectWithLength(value, buf, lengthCache, parameter, async);
91+
8992
if (parameter?.ConvertedValue != null)
9093
value = parameter.ConvertedValue;
9194
var s = value as string ?? JsonConvert.SerializeObject(value, _settings);

0 commit comments

Comments
 (0)