Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How not to store specific variable in database when using setValue(Object)?

I'm trying to minimize the amount of data I have in my database.

I have a class called user which looks like the following:

class User {
    
    private Position pos;
    private String uid;}

Right now my database looks like:

uid{
    pos{ L1=value,
         L2=value
       }
   uid=value
}

Very minimized, in fact I'd prefer not even to have the additional uid because the key is the uid which is the unique identifier anyways.

Now, I want to add an additional variable called working into the class.

class User{
    private Position pos;
    private String uid;
    private boolean working;
}

Using ref.setValue(User), the database now becomes this:

uid{
    pos{ L1=value,
         L2=value
       }
   uid=value,
   working=value
}

I do not need to store the working variable in the database, that's just needless information to send. How do I not send this over, but keep it in my User class? The same goes for the additional String uid. I would prefer to remove that from the database as well, but keep it in the class.

like image 500
jtompkj Avatar asked Jul 29 '16 17:07

jtompkj


1 Answers

Check out the @Exclude and IgnoreExtraProperties.

https://firebase.google.com/docs/reference/android/com/google/firebase/database/Exclude

class User{
 private Position pos;
 private String uid;
 @Exclude
 private boolean working;
}
like image 140
Veeresh Charantimath Avatar answered Sep 21 '22 00:09

Veeresh Charantimath