firebase / firebase/firebase-android-sdk

enum deserialization of missing values to null

Open
#1,418 15 comments 1 reaction 1 assignee Claimed by @dconeybe View on GitHub
api: database api: firestore type: feature request
Dominant language
Java
Stars
2.6k
Forks
710
Avg merge
2d 23h
Merged PRs (30d)
34

Description

My domain class has one field as an enum.

Recently I decided to change the enum values for a better readeability. But know when trying to load users from firebase i get the exception.


`Giveaway giv = ds.getValue(Giveaway.class);`

```
Process: com.tomatedigital.instagramgiveawaywinner, PID: 21593
com.google.firebase.database.DatabaseException: Could not find enum value of com.tomatedigital.giveawaymaster.domain.CommentListType for value "COMMON_NAMES"
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToEnum(com.google.firebase:firebase-database@@19.2.1:314)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-database@@19.2.1:229)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToType(com.google.firebase:firebase-database@@19.2.1:178)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$100(com.google.firebase:firebase-database@@19.2.1:47)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.deserialize(com.google.firebase:firebase-database@@19.2.1:592)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.deserialize(com.google.firebase:firebase-database@@19.2.1:562)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(com.google.firebase:firebase-database@@19.2.1:432)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-database@@19.2.1:231)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToCustomClass(com.google.firebase:firebase-database@@19.2.1:79)
at com.google.firebase.database.DataSnapshot.getValue(com.google.firebase:firebase-database@@19.2.1:203)
at com.tomatedigital.giveawaymaster.firabase.LoginValueEventListener$3.onDataChange(LoginValueEventListener.java:178)
at com.google.firebase.database.Query$1.onDataChange(com.google.firebase:firebase-database@@19.2.1:179)
at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database@@19.2.1:75)
at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database@@19.2.1:63)
at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database@@19.2.1:55)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
```

`COMMON_NAMES` was changed to something else.

I completely understand the reason of this exception... my question is "are there any workaround?"...

I wish i could tell firebase to map unexisting enum values to `null` or any value, so then i could manually deal with them...

Is a very complicated restriction to throw a fatal exception like this on deserialization for a missing value... it means that ALL APPS RUNNING FIREBASE WONT BE ALLOWED TO REMOVE ENUM VALUES FOREVER...

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.