jsonOptional<T> function
Reads eiher a null
or what builder
reads from a JsonReader.
If the next value of builder
is null
, then the result
is null
, otherwise returns the same value as builder
on reader
.
Can be used as, for example:
var optionalJsonInt = jsonOptional(jsonInt);
var optionalInt = optionalJsonInt(reader); // int or null
Implementation
JsonBuilder<T?> jsonOptional<T>(JsonBuilder<T> builder) =>
(JsonReader reader) => reader.tryNull() ? null : builder(reader);