-
Notifications
You must be signed in to change notification settings - Fork 578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GenericTypeIndicator missing from firestore library but required #222
Comments
Thanks for pointing this out! For the moment you can work around this in a few ways:
class DudeWhateverHolder {
public String dude;
public int whatever;
}
snapshot.toObject(DudeWhateverHolder.class);
String dude = snapshot.get("dude", String.class);
int whatever = snapshot.get("whatever", Integer.class);
class DudeWhateverMap extends HashMap<String, MyClass> {}
// Usage
snapshot.toObject(DudeWhateverMap.class);
public static <T> Map<String, T> toMapWithValues(Class<T> valueClass, DocumentSnapshot snapshot) {
Map<String, T> result = new HashMap<>();
for (String key : snapshot.getData().keys()) {
T value = snapshot.get(key, valueClass);
result.put(key, value);
}
return result;
}
// Usage
toMapWithValues(MyClass.class, snapshot); Of course built-in support would be better, but the error message is erroneously pointing to a feature that doesn't exist rather than just a missing class. Fixing this isn't trivial and will require an additional public API review process so it won't happen too quickly. Note that for heterogeneous values like those in your example ( |
Oh, and to be clear, I've added this to our backlog, but given the available workarounds we'll prioritize this along with other feature work. |
Still needed! |
Nothing yet? |
We are still busy with a lot of other work, so unfortunately you have to apply the existing workarounds. |
If no time to implement it, at least, workarounds should be in the documentation. |
No news here? |
Hi @Skaldebane , The team is discussing this feature request (b/123794691). In the meantime we will update the error message. |
[Port of firebase/firebase-js-sdk#1120] See firebase/firebase-ios-sdk#1499 This reworks our "user listener" into a "credential change listener" that fires on any token change, even if the User did not change. This allows us to restart our streams (but not switch mutation queues, etc.) on token changes.
[REQUIRED] Step 2: Describe your environment
[REQUIRED] Step 3: Describe the problem
Steps to reproduce:
What Happened:
When you try to retrieve a object and turn it to a object with a generic with type parameters EX( a Map/HashMap) you get the error
Could not deserialize object. Class java.util.HashMap has generic type parameters, please use GenericTypeIndicator instead
What would normally happen is using GenericTypeIndicator to define the types but that class isn't included with the firebase-firestore library for android and is only included in the firebase-database (
com.firebase.client.GenericTypeIndicator
) android library.To Reproduce:
Create a collection and a document with values ex:
{
"dude":"wow",
"whatever":32,
}
Retrieve item and convert to object with a with a generic map
documentSnapshot.toObject(typeParameterClass)
Ex.:
documentSnapshot.toObject(HashMap.class)
Relevant Code:
The text was updated successfully, but these errors were encountered: