getJsonString method

String getJsonString()

For internal use only. Implementation detail that may change anytime.

This method is used instead of toJson, as we need to output valid JS that is not valid JSON. The toJson method is intentionally omitted, to produce an error if someone tries to convert this object to JSON instead of using the getJsonString method.

Implementation

String getJsonString() {
  if (this._idOnly) {
    return '"$id"';
  } else {
    final result = <String, dynamic>{};

    result['id'] = id;
    result['name'] = name;

    if (email != null) {
      result['email'] = email;
    }

    if (phone != null) {
      result['phone'] = phone;
    }

    if (availabilityText != null) {
      result['availabilityText'] = availabilityText;
    }

    if (locale != null) {
      result['locale'] = locale;
    }

    if (photoUrl != null) {
      result['photoUrl'] = photoUrl;
    }

    if (role != null) {
      result['role'] = role;
    }

    if (welcomeMessage != null) {
      result['welcomeMessage'] = welcomeMessage;
    }

    if (custom != null) {
      result['custom'] = custom;
    }

    return json.encode(result);
  }
}