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(
'$expression == \'true\' || $expression == \'1\' ? true : $expression == \'false\' || $expression == \'0\' ? false : throw FormatException(\'Invalid bool format\', $expression)',
);
if (_isNullable) {
buffer.write(' : null');
}
return buffer.toString();
}