gpt4 book ai didi

java - firebase android 基于类的更新不考虑字段名称的大小写

转载 作者:行者123 更新时间:2023-11-29 21:00:25 24 4
gpt4 key购买 nike

我声明了以下类(注意大小写选择):

public class User{

private String DisplayName;
private Boolean Proxy = false;

@SuppressWarnings("unused")
public User(){

}
public User(String DisplayName, Boolean Proxy) {
this.DisplayName = DisplayName;
this.Proxy = Proxy;
}

public String getDisplayName() {
return DisplayName;
}

public void setDisplayName(String DisplayName) {
this.DisplayName = DisplayName;
}

public Boolean getProxy() {
return Proxy;
}
}

然后我调用:

ref.child("People/123").setValue(userList);

哪里userListArrayList<User> 的实例

然而,创建的节点并不像我想象的那样尊重大写。他们创造了 displayNameproxy而不是预期的 DisplayNameProxy以匹配声明。

这是预期的行为吗?有没有办法让它尊重字段名称?

最佳答案

您似乎假设 Firebase 存储中的名称基于您的字段 DisplayNameProxy

但是如果你阅读 the documentation on setValue它说:

The class must define public getters for the properties to be assigned. Properties without a public getter will be set to their default value when an instance is deserialized

这看起来像是 Firebase 使用 the Java bean definition of properties (因为 Java 没有 native 属性),这意味着它们派生自(公共(public))方法名称 getDisplayNamegetProxy

要从 getDisplayName 中确定属性名称,您需要去除 get 前缀并将该字母后的第一个字母设为小写。这正是您在 Firebase 存储中看到的属性名称。

关于java - firebase android 基于类的更新不考虑字段名称的大小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26292731/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com