Reputation: 783
I have an object in a firebase database that I am trying to extract from a snapshot.
The JSON object from firebase is:
"-KoVHZ8YVll0RiI2GwKb" : {
"name" : "Name 1",
"phone_number" : "4443335555"
}
I am trying to safe it in an object that looks like this
public class Contact {
private String mName;
private String mPhoneNumber;
public Contact() {
mName = "";
mPhoneNumber = "";
}
public String getName() { return mName; }
public String getPhoneNumber() { return mPhoneNumber; }
public void setName(final String name) { mName = name; }
public void setPhoneNumber(final String phoneNumber) { mPhoneNumber = phoneNumber; }
}
I am calling
Contact contact = snapshot.getValue(Contact.class);
The contact object only has the name populated and not the phone number. The documentation just states that there must be public getters and an empty constructor in order for this to work. My guess is something is wrong with my naming convention anyone have any ideas?
EDIT
I am aware that I can extract the data out by doing this:
mName = (String) snapshot.child("nane").getValue();
mPhoneNumber = (String) snapshot.child("phone_number").getValue();
But then what is the point of creating the P.O.J.O.?
Upvotes: 1
Views: 132
Reputation: 786
Make your Contact.java like this:
@IgnoreExtraProperties
public class Contact {
private String name;
private String phone_number;
public Contact() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone_number() {
return phone_number;
}
public void setPhone_number(String phone_number) {
this.phone_number = phone_number;
}
}
Upvotes: 1