TobiasBuchholz / Plugin.Firebase

Wrapper around the native Android and iOS Firebase Xamarin SDKs
MIT License
211 stars 49 forks source link

Firestore: Couldn't cast property 'foo' of 'bar' because it's not contained in the dictionary #174

Closed tranb3r closed 1 year ago

tranb3r commented 1 year ago

Hi,

I'm seen in my logcat this line appearing quite frequently: [Plugin.Firebase] Couldn't cast property 'foo' of 'bar' because it's not contained in the dictionary

Why did you decide to log something when a property is null? Why not simply skip properties that have not been set in the firestore document?

https://github.com/TobiasBuchholz/Plugin.Firebase/blob/7c9358d68b41239c00e7d214a93ab2b1b4ac591f/src/Firestore/Platforms/Android/Extensions/JavaObjectExtensions.cs#L152

Thanks

TobiasBuchholz commented 1 year ago

Hi, this message appears when the IFirebaseObject model class contains a FirestoreProperty that isn't contained in the firestore document and I thought it would be useful for people to get notified when this is the case by accident. If you don't want to see the message, you could just remove the property right?

tranb3r commented 1 year ago

Here is example: Let's imagine of a document for your users with 3 properties: firstName, middleName, lastName. You define the middleName FirestoreProperty in the model class for your user document. But some people do not have a middleName. So when you deserialize the documents, sometimes you get a null value for middleName. It's totally ok and expected. Having a log in this situation is not that useful. In this example, how removing the middleName property would help? You would just ignore the middleName of every user, which is not what you want to do.

Kapusch commented 1 year ago

From what I recollect, if the value stored in Firebase is null, then you won't be notified by this warning

TobiasBuchholz commented 1 year ago

Okay, I see you point. I just personally assumed it would be helpful for people to get this message bu if it's more bothering than helpful, it might as well be left out.

tranb3r commented 1 year ago

Maybe this could be done only in Debug and ignored in Release ?

TobiasBuchholz commented 1 year ago

Released in Firestore version 2.0.3 und Bundled version 2.0.4 ✌️

tranb3r commented 1 year ago

Danke schön