android - Firebase serialization names -
i created object send data firebase. example, use firebase user example:
public class user { public string username; public string email; public user() { // default constructor required calls datasnapshot.getvalue(user.class) } public user(string username, string email) { this.username = username; this.email = email; } }
i want encode property names sent firebase. keys sent using variable names. want encode keys useraname
, email
, gson
doing. don't want change variable names.
@serializatename("username") public string username; @serializatename("username") public string email;
i used @serializatename()
, not working. same @propertyname
used firebse, not working. can use in order serializare custom keys?
update 1
public class pojo { @propertyname("guid") public string guid; @propertyname("name") public string name; public string getpojoguid() { return guid; } public void setpojoguid(string guid) { this.guid = guid; } }
as can see in image, saves keys based on variable names. changed property name annotation 1 field , when save it, ignores it, when change variable name, save new entry key new varialbe name.
in this documentation method tomap()
. if that, working (is not convenient me), not working @propertyname
.
update 2
if mark getters , setters @exclude
, class @ignoreextraproperties
working. don't have use tomap()
method example documetation. using specified name @propertyname
. not thing in opinion, create confuses.
the firebase sdk uses annotation finds property whenever gets or sets value. means need consider how firebase gets/sets value, , annotate each place looks.
since you're declaring getter
method, firebase use value of property. use field setting value. annotation needs 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 , setters, annotation need on those, not on 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; } }
Comments
Post a Comment