parseEncode function

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

Custom json encoder for types related to parse

Implementation

dynamic parseEncode(dynamic value, {bool full = false}) {
  if (value is Uint8List) {
    return _encodeUint8List(value);
  }

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

  if (value is Iterable) {
    return value.map<dynamic>((dynamic value) {
      return parseEncode(value, full: full);
    }).toList();
  }

  if (value is _ParseArray) {
    return value.toJson(full: full);
  }

  if (value is _ParseNumber) {
    return value.toJson(full: full);
  }

  if (value is _ParseOperation) {
    return value.toJson(full: full);
  }

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

  if (value is ParseGeoPoint) {
    return value.toJson(full: full);
  }

  if (value is ParseFileBase) {
    return value.toJson(full: full);
  }

  if (value is ParseRelation) {
    return value.toJson(full: full);
  }

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

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

  return value;
}