DocumentReference<T extends dynamic>.fromJson constructor

DocumentReference<T extends dynamic>.fromJson(
  1. FirebaseFirestore firestore,
  2. Map<String, Object?> json, {
  3. FirestoreDataConverter<T>? converter,
})

Builds a DocumentReference of firestore from a JSON map created by toJson, optionally with a converter.

Throws an ArgumentError if json does not have that shape or referencePath is not a document path. This is the JS SDK DocumentReference.fromJSON().

Implementation

factory DocumentReference.fromJson(
  FirebaseFirestore firestore,
  Map<String, Object?> json, {
  FirestoreDataConverter<T>? converter,
}) {
  final Object? referencePath = json['referencePath'];
  if (json['type'] != jsonType || referencePath is! String) {
    throw ArgumentError.value(
      json,
      'json',
      'Not a JSON representation of a DocumentReference',
    );
  }
  final ResourcePath path = ResourcePath.fromString(referencePath);
  if (path.length == 0) {
    throw ArgumentError.value(
      json,
      'json',
      'The referencePath must be a document path',
    );
  }
  return DocumentReference<T>._forPath(path, firestore, converter);
}