shared/json library
Checked access to a decoded response body.
HttpService's verbs hand back whatever jsonDecode produced, so every
parser downstream is one unchecked cast away from a TypeError raised from
inside the SDK - which reads as an SDK bug rather than as a response that was
not the shape the endpoint promised. FindResultDto, Response.fromJson,
_cacheUser and decodeToken each grew their own version of this check; this
is the same idea in one place, for the cases that had none.
Functions
-
asJsonObject(
dynamic body, String what) → Map< String, dynamic> -
bodyas a JSON object, or a FormatException naming what arrived instead. -
optionalDateTime(
Map< String, dynamic> json, String key, String what) → DateTime? -
The DateTime at
keywhen there is one, null when the field is absent, and a FormatException when it is present but not a date. -
optionalString(
Map< String, dynamic> json, String key, String what) → String? -
The string at
keywhen there is one, null when the field is absent or null, and a FormatException when it is present as something other than a string. -
optionalStringList(
Map< String, dynamic> json, String key, String what) → List<String> ? -
The strings at
keywhen there are any, null when the field is absent, and a FormatException when it is present as something other than a list of strings. -
requireDateTime(
Map< String, dynamic> json, String key, String what) → DateTime -
The DateTime at
key, or a FormatException naming the field. -
requireString(
Map< String, dynamic> json, String key, String what, {bool allowEmpty = false}) → String -
The string at
key, or a FormatException naming the field that was wrong.