在Firebase中将孩子名字的大写字母作为首字母 [英] Make first letter of child name capital in Firebase

查看:79
本文介绍了在Firebase中将孩子名字的大写字母作为首字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Order对象将数据推送到Firebase,问题是我想要每个子名称的首字母大写.我将属性定义为投诉",但在Firebase中,该属性仍显示为投诉",我不知道该怎么做.

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.

Firebase的当前结构:

The current structure of the Firebase:

我想要的结构:

我这样定义属性:

@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;
}
}

我这样将数据推送到Firebase:

I push data to Firebase like this:

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

推荐答案

Firebase JSON序列化名称由

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;
    }

}

注释必须同时在getter和setter上.或者,您可以只使用公共字段并将类简化为:

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;
}

这篇关于在Firebase中将孩子名字的大写字母作为首字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆