Firebase serialization names
The Firebase SDK uses the annotation it finds for the property whenever it gets or sets its value. That means you need to consider how Firebase gets/sets the value, and annotate each place it looks.
Since you're declaring a getter
method, Firebase will use that to get the value of the property. It will use the field for setting the value. So the annotation needs to be on both:
public class Pojo {
@PropertyName("Guid")
public String guid;
@PropertyName("Name")
public String name;
@PropertyName("Guid")
public String getPojoGuid() {
return guid;
}
@PropertyName("Guid")
public void setPojoGuid(String guid) {
this.guid = guid;
}
}
If you'd have getters and setters, the annotation would need to be on those, but not on the fields anymore:
public class Pojo {
private String guid;
private String name;
@PropertyName("Guid")
public String getPojoGuid() {
return guid;
}
@PropertyName("Guid")
public void setPojoGuid(String value) {
guid = value;
}
@PropertyName("Name")
public void setPojoGuid(String guid) {
this.guid = guid;
}
@PropertyName("Name")
public void setPojoGuid(String value) {
name = value;
}
}
@PropertyName :
Marks a field to be renamed when serialized. link
you have to use @PropertyName
with public fields and no need for getters/setters
What you are looking for is the feature of SDK Version 9.2 in which you can now use a new @PropertyName
attribute to specify the name to use when serializing a field from a Java model class to the database. This replaces the @JsonProperty
attribute.
@PropertyName("Username")
public String username;
@PropertyName("Email")
public String email;
See also this post in which Frank van Puffelen explains very clearly this concept.