toJson method

Map<String, String> toJson()

Returns a map with the identifier as key and the value as value. This is used to provide extensions in future versions.

The security identifier can easily by extended by adding a new field and therefore we don't have to change any method signature.

Implementation

Map<String, String> toJson() {
  if (symbol != null) {
    return <String, String>{'symbol': symbol.toString()};
  } else if (isin != null) {
    return <String, String>{'isin': isin.toString()};
  } else if (cusip != null) {
    return <String, String>{'cusip': cusip.toString()};
  } else if (wkn != null) {
    return <String, String>{'wkn': wkn.toString()};
  } else {
    // Never reached because of assert in constructor
    throw Exception('No identifier found');
  }
}