generateDeserializer method
Generates code that deserializes an expression
representing a String to an instance of the type.
An implementation to deserialize a DateTime by calling the DateTime.parse method could be as simple as:
String generateDeserializer(String expression) => 'DateTime.parse($expression)';
Implementation
@override
String generateDeserializer(String expression) {
final buffer = StringBuffer();
if (_isNullable) {
buffer.write('$expression != null ? ');
}
buffer.write(
'\$${_type}EnumMap.entries.singleWhere((${_type.camelCase}EnumMapEntry) => ${_type.camelCase}EnumMapEntry.value == $expression, orElse: () => throw ArgumentError(\'`\$$expression` is not one of the supported values: \${\$${_type}EnumMap.values.join(\', \')}\')).key',
);
if (_isNullable) {
buffer.write(' : null');
}
return buffer.toString();
}