Parcelable in firebase pojo

Well this blog post ain’t no comparsion of Parcelable vs POJO vs Serialization. That being said, we have seen this doc explaining in Firebase about using objects for data reads & writes.

User Objectlink
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@IgnoreExtraProperties
public class User {
public String username;
public String email;
public User() {
// Default constructor required for calls to DataSnapshot.getValue(User.class)
}
public User(String username, String email) {
this.username = username;
this.email = email;
}
}

Well if you feel parcelable is a right fit for parsing data. Then try using the below code for data reads/writes.

Example Object
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public class User implements Parcelable {
public String username;
public String email;
public Long time;
public User(Parcel in) {
// Read parcelable contents
}
public static final Parcelable.Creator<User> CREATOR
= new Parcelable.Creator<User>() {
public User createFromParcel(Parcel in) {
return new User(in);
}
public User[] newArray(int size) {
return new User[size];
}
};
//getters and setter methods
//getting time info
public Map<String,String> getTime() {
return ServerValue.TIMESTAMP;
}
//setting time info
public void setTime(Long updated_time) {
this.time = updated_time;
}
}

Here timestamps from Firebase are Map objects for reads and writes are long types. Well that is it, I will put out performance reviews regarding parsing time, memory consumptions etc..