toJSON method

  1. @override
dynamic toJSON()
override

Implementation

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

  for (final field in fields) {
    if (field is JsonString ||
        field is JsonNumber ||
        field is JsonBoolean ||
        field is JsonInteger ||
        field is JsonDouble) {
      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;
}