Skip to content

Commit 5ca0d8e

Browse files
authored
Support serialization of null (#111)
1 parent ca36427 commit 5ca0d8e

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/Dahomey.Cbor/Cbor.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public static Task SerializeAsync<T>(
225225

226226
[MethodImpl(MethodImplOptions.AggressiveInlining)]
227227
public static Task SerializeAsync(
228-
object input,
228+
object? input,
229229
Type inputType,
230230
Stream stream,
231231
CborOptions? options = null,
@@ -250,15 +250,22 @@ public static void Serialize<T>(
250250

251251
[MethodImpl(MethodImplOptions.AggressiveInlining)]
252252
public static void Serialize(
253-
object input,
253+
object? input,
254254
Type inputType,
255255
in IBufferWriter<byte> buffer,
256256
CborOptions? options = null)
257257
{
258-
options ??= CborOptions.Default;
259258
CborWriter writer = new CborWriter(buffer);
260-
ICborConverter converter = options.Registry.ConverterRegistry.Lookup(inputType);
261-
converter.Write(ref writer, input);
259+
if (input is null)
260+
{
261+
writer.WriteNull();
262+
}
263+
else
264+
{
265+
options ??= CborOptions.Default;
266+
ICborConverter converter = options.Registry.ConverterRegistry.Lookup(inputType);
267+
converter.Write(ref writer, input);
268+
}
262269
}
263270

264271
/// <summary>

0 commit comments

Comments
 (0)