toJson method

  1. @mustCallSuper
  2. @override
Map<String, dynamic> toJson()

Converts this class object into a JSON value.

Implementation

@mustCallSuper
@override
Map<String, dynamic> toJson() {
  final result = {
    "forms": forms.toJson(),
    ...additionalFields,
  };

  final keyValuePairs = [
    ("@type", atType),
    ("title", title),
    ("titles", titles),
    ("description", description),
    ("descriptions", descriptions),
    ("uriVariables", uriVariables),
  ];

  for (final (key, value) in keyValuePairs) {
    final dynamic convertedValue;

    switch (value) {
      case null:
        continue;
      case Map<String, DataSchema>():
        convertedValue = value.toJson();
      default:
        convertedValue = value;
    }

    result[key] = convertedValue;
  }

  return result;
}