Skip to content

Adding QueryDocumentSnapshot#2738

Merged
schmidt-sebastian merged 7 commits into
googleapis:masterfrom
FirebasePrivate:mrschmidt-querydocumentsnapshot
Jan 17, 2018
Merged

Adding QueryDocumentSnapshot#2738
schmidt-sebastian merged 7 commits into
googleapis:masterfrom
FirebasePrivate:mrschmidt-querydocumentsnapshot

Conversation

@schmidt-sebastian

Copy link
Copy Markdown
Contributor

This is based on user feedback and changes the DocumentSnapshot API to return null for non-existing documents (instead of throwing an Exception). Since Queries never return null documents, this PR also introduces QueryDocumentSnapshot, which overrides the DocumentSnapshot methods to be non-nullable.

Addresses b/71489271 and b/69365491

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jan 2, 2018
/**
* A DocumentSnapshot contains data read from a document in a Firestore database. The data can be
* extracted with the getData or get methods.
* extracted with the getData() or get() methods.

This comment was marked as spam.

This comment was marked as spam.

Map<String, Object> decodedFields = new HashMap<>();
for (Map.Entry<String, Value> entry : fields.entrySet()) {
decodedFields.put(entry.getKey(), decodeValue(entry.getValue()));
if (fields != null) {

This comment was marked as spam.

This comment was marked as spam.

@Override
public Map<String, Object> getData() {
Map<String, Object> result = super.getData();
Preconditions.checkNotNull(result, "Data in a QueryDocumentSnapshot should be non-null");

This comment was marked as spam.

This comment was marked as spam.

@Override
public <T> T toObject(@Nonnull Class<T> valueType) {
T result = super.toObject(valueType);
Preconditions.checkNotNull(result, "Object in a QueryDocumentSnapshot should be non-null");

This comment was marked as spam.

This comment was marked as spam.

@pongad

pongad commented Jan 3, 2018

Copy link
Copy Markdown
Contributor

Some stylistic comments. @garrettjonesgoogle PTAL

/**
* A DocumentSnapshot contains data read from a document in a Firestore database. The data can be
* extracted with the getData or get methods.
* extracted with the {@code getData()} or {@code get()} methods.

This comment was marked as spam.

This comment was marked as spam.

@@ -0,0 +1,87 @@
/*
* Copyright 2017 Google Inc. All Rights Reserved.

This comment was marked as spam.

This comment was marked as spam.

import org.threeten.bp.Instant;

/**
* A QueryDocumentSnapshot contains data read from a document in your Firestore database as part of

This comment was marked as spam.

This comment was marked as spam.

@garrettjonesgoogle garrettjonesgoogle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after the copyright line is fixed

@@ -0,0 +1,87 @@
/*
* Copyright 2018 Google Inc. All Rights Reserved.

This comment was marked as spam.

This comment was marked as spam.

@schmidt-sebastian schmidt-sebastian merged commit 225435d into googleapis:master Jan 17, 2018
suztomo pushed a commit that referenced this pull request Mar 9, 2026
chingor13 pushed a commit that referenced this pull request Mar 24, 2026
Co-authored-by: Lawrence Qiu <lawrenceqiu@google.com>
chingor13 pushed a commit that referenced this pull request Mar 30, 2026
…v3.36.1 (#2738)

* deps: update dependency com.google.cloud:sdk-platform-java-config to v3.36.1

* chore: add program to regenerate reflect-config.json

* chore: regenerate reflect-config.json for protobuf 1.68.0

---------

Co-authored-by: BenWhitehead <BenWhitehead@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants