toJSON method

  1. @override
Map<String, dynamic> toJSON()
override

Implementation

@override
Map<String, dynamic> toJSON() {
  final Map<String, dynamic> result = {};

  for (final field in fields) {
    if (field is JsonString || field is JsonNumber || field is JsonBoolean) {
      result[field.name] = field.value;
      continue;
    }
    if (field is JsonDate) {
      result[field.name] = field.value?.toIso8601String();
      continue;
    }
    if (field is JsonObject) {
      result[field.name] = field.value?.toJSON();
      continue;
    }
    if (field is JsonList) {
      result[field.name] =
          field.value?.map((element) => element.toJSON()).toList();
      continue;
    }
  }

  return result;
}