toJson method

Map<String, dynamic> toJson({
  1. bool full = false,
  2. bool forApiRQ = false,
  3. bool allowCustomObjectId = false,
})

Converts object to String in JSON format

Implementation

Map<String, dynamic> toJson({
  bool full = false,
  bool forApiRQ = false,
  bool allowCustomObjectId = false,
}) {
  final Map<String, dynamic> map = <String, dynamic>{
    keyVarClassName: parseClassName,
  };

  if (objectId != null) {
    map[keyVarObjectId] = objectId;
  }

  if (createdAt != null) {
    map[keyVarCreatedAt] = _parseDateFormat.format(createdAt!);
  }

  if (updatedAt != null) {
    map[keyVarUpdatedAt] = _parseDateFormat.format(updatedAt!);
  }

  final target = forApiRQ ? _unsavedChanges : _getObjectData();
  target.forEach((String key, dynamic value) {
    if (!map.containsKey(key)) {
      map[key] = parseEncode(value, full: full);
    }

    if (forApiRQ &&
        value is _ParseRelation &&
        !value.shouldIncludeInRequest()) {
      map.remove(key);
    }
  });

  if (forApiRQ) {
    map.remove(keyVarCreatedAt);
    map.remove(keyVarUpdatedAt);
    map.remove(keyVarClassName);
    //map.remove(keyVarAcl);

    if (!allowCustomObjectId) {
      map.remove(keyVarObjectId);
    }
    map.remove(keyParamSessionToken);
  }

  return map;
}