parseEncode function

dynamic parseEncode (
  1. dynamic value,
  2. {bool full}
)

Custom json encoder for types related to parse

Implementation

dynamic parseEncode(dynamic value, {bool full}) {
  full ??= false;

  if (value is Uint8List) {
    return _encodeUint8List(value);
  }

  if (value is DateTime) {
    return _encodeDate(value);
  }

  if (value is List) {
    return value.map<dynamic>((dynamic value) {
      return parseEncode(value);
    }).toList();
  }

  if (value is Map) {
    value.forEach((dynamic k, dynamic v) {
      value[k] = parseEncode(v);
    });
  }

  if (value is ParseGeoPoint) {
    return value;
  }

  if (value is ParseFileBase) {
    return value;
  }

  if (value is ParseRelation) {
    return value;
  }

  if (value is ParseObject || value is ParseUser) {
    if (full) {
      return value.toJson(full: full);
    } else {
      return value.toPointer();
    }
  }

  if (value is ParseACL) {
    return value.toJson();
  }

  return value;
}