Make first letter of child name capital in Firebase

安稳与你 提交于 2020-07-22 06:08:07

问题


I push data to Firebase using Order object, the question is I want the first letter of every child name capital. I defined the property like "Complain" but in Firebase it still shows as "complain", I dont know how to make it.

The current structure of the Firebase:

The current structure of the Firebase

The structure I want:

The structure I want

I defined the property like this:

@Data
public class Order implements Serializable {

@SerializedName("Complain")
private String Complain;

public Order() {
 Complain = "";
}

public String getComplain() {
    return Complain;
}

public void setComplain(String complain) {
    Complain = complain;
}
}

I push data to Firebase like this:

Map<String, Object> map = new HashMap<>();
map.put(orderSavePath, order);
reference.updateChildren(map).addOnCompleteListener(listener);

回答1:


The Firebase JSON serialization name is controlled by the annotation PropertyName.

public class Order implements Serializable {

    private String Complain;

    public Order() {
     Complain = "";
    }

    @PropertyName("Complain")
    public String getComplain() {
        return Complain;
    }

    @PropertyName("Complain")
    public void setComplain(String complain) {
        Complain = complain;
    }

}

The annotation needs to be on both the getter and the setter. Alternatively you can just use public fields and reduce the class to:

public class Order {
    @PropertyName("Complain")
    public String Complain;
}


来源:https://stackoverflow.com/questions/45809197/make-first-letter-of-child-name-capital-in-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!