I am using Firebase Database and bellow specified is my java class structure. After saving my first object in Firebase database I realised that the keys are automatically converted to lower case keys in Firebase database. is there any solution to retain the case while saving my objects.
public class Student {
String NAME;
String ROLL_NUMBER;
String USER_NAME;
String MAIL_ID;
String PASSWORD;
public Student() {
}
public Student(String NAME, String ROLL_NUMBER, String PASSWORD, String MAIL_ID, String USER_NAME) {
this.NAME = NAME;
this.ROLL_NUMBER = ROLL_NUMBER;
this.PASSWORD = PASSWORD;
this.MAIL_ID = MAIL_ID;
this.USER_NAME = USER_NAME;
}
public String getNAME() {
return NAME;
}
public String getROLL_NUMBER() {
return ROLL_NUMBER;
}
public String getPASSWORD() {
return PASSWORD;
}
public String getMAIL_ID() {
return MAIL_ID;
}
public String getUSER_NAME() {
return USER_NAME;
}
}
I have also tried with @SerializedName
also doesn't make any difference.
Here is key value pairs in Firebase database
"-LMqLmS09gGKjR-s9CML" : {
"mail_ID" : "gyana@gmail.com",
"name" : "Gyanaranjan",
"password" : "123456",
"roll_NUMBER" : "1001028",
"user_NAME" : "gyan1028"
},
"-LMqMPegnxHp8l4efj_J" : {
"mail_ID" : "shyamu@gmail.com",
"name" : "Shyama G",
"password" : "113456",
"roll_NUMBER" : "1001056",
"user_NAME" : "shyamla1056"
}
According to your comments, you need to know that Firebase real-time database follows the Java Bean
property naming convention for mapping between the Java object and the fields in the node.
Here are some examples of how specific method names map to property names (and this field names):
public String getName(); // getter for property "name"
public void setName(String name); // setter for property "name"
public String getRollNumber(); // getter for property "rollNumber"
public void setRollNumber(String rollNumber); // setter for property "rollNumber"
It is not mandatory to use getters
and setters
. In all of these cases you can also go without the getter/setter and use only a public field:
public String name;
public String rollNumber;
Which is perfectly safe. So it is not required to have both getters and setters. If you have only a getter, Firebase will set the corresponding field directly. This does however require that your field name follows the naming conventions, so that Firebase can find the correct field to set.
For another information, you can also take a look at my answer from this post.