From 62aa57af803c6ad09f10e979f2a069168b4d167c Mon Sep 17 00:00:00 2001 From: Matthias Kunnen Date: Sat, 23 Jan 2021 22:20:00 +0000 Subject: [PATCH] Deal with null and undefined in mapType documentation --- readme.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 8fe3b02..ef3a8ff 100644 --- a/readme.md +++ b/readme.md @@ -76,13 +76,13 @@ import {jsonObject, jsonMember, TypedJSON} from 'typedjson'; import * as Decimal from 'decimal.js'; // Or any other library your type originates from TypedJSON.mapType(BigInt, { - deserializer: json => new BigInt(json), - serializer: value => value.toString(), + deserializer: json => value == null ? value : new BigInt(json), + serializer: value => value == null ? value : value.toString(), }); TypedJSON.mapType(Decimal, { - deserializer: json => new Decimal(json), - serializer: value => value.toString(), + deserializer: json => value == null ? value : new Decimal(json), + serializer: value => value == null ? value : value.toString(), }); @jsonObject