handle<V> method
V
handle<V>({
- required ParameterType parameterType,
- required V value,
- required String name,
- Kind? kind,
- V? defaultConstant,
- String? jsonName,
- List<
Trait> ? tags,
override
Handles calls to positional, optionalPositional, required, call, optional.
Implementation
@override
V handle<V>({
required ParameterType parameterType,
required V value,
required String name,
Kind? kind,
V? defaultConstant,
String? jsonName,
List<Trait>? tags,
}) {
if (tags != null && tags.contains(Trait.noSerialization)) {
return value;
}
// JSON name defaults to Dart identifier
jsonName ??= name;
// Does the JSON object contain the JSON field?
final jsonObject = this.jsonObject;
if (!jsonObject.containsKey(jsonName)) {
// No, use default value.
return value;
}
// Get JSON value
var jsonValue = this.jsonObject[jsonName];
// Simple case?
if (jsonValue is V) {
return jsonValue;
}
// Just in case the JSON tree has `int` rather than `double`,
// convert it to double for consistency:
if (jsonValue is int) {
jsonValue = jsonValue.toDouble();
}
// Determine kind.
//
// If V is nullable:
// No need for toNullable() because already handled `null` case when we
// did `jsonValue is V`.
final actualKind = kind ?? Kind.find<V>();
return actualKind.decodeJsonTree(jsonValue);
}