【发布时间】:2019-05-01 17:07:20
【问题描述】:
我一直在将 POJO 添加到 Firestore,它会自动将它们解释为数据库的 JSON 对象。但是,我想让我的 POJO 具有 Firestore 所称的 reference 类型。属性类型是否只是DocumentReference 而不是String?
我正在使用 Java 开发一个 Android 项目。
这是 Firebase 文档中的自定义对象示例。
public class City {
private String name;
private String state;
private String country;
private boolean capital;
private long population;
private List<String> regions;
public City() {}
public City(String name, String state, String country, boolean capital, long population, List<String> regions) {
// ...
}
public String getName() {
return name;
}
public String getState() {
return state;
}
public String getCountry() {
return country;
}
public boolean isCapital() {
return capital;
}
public long getPopulation() {
return population;
}
public List<String> getRegions() {
return regions;
}
}
然后添加到数据库中
City city = new City("Los Angeles", "CA", "USA",
false, 5000000L, Arrays.asList("west_coast", "sorcal"));
db.collection("cities").document("LA").set(city);
【问题讨论】:
标签: java android firebase google-cloud-firestore