toJson method Null safety

Map toJson()

Implementation

Map toJson(){
  Map result = {};

  if (localizedMessage != null) result.addAll({"localizedMessage": localizedMessage});
  if (message != null) result.addAll({"message": message});
  if (string != null) result.addAll({"string": string});
  if (stackTrace != null) result.addAll({"stackTrace": stackTrace});

  return result;
}