我尝试在Kotlin Android项目中使用Firebase Firestore。当我试图用DocumentSnapshot.toObject(类valueType)实例化一个对象时,我遇到了一个问题。我试图用id eq 1从一个名为“news”的集合中读取一个对象,我可以读取数据,但是API不允许我将文档放入自定义对象中。
News.kt
data class News(
val id : String? = "",
val value : String? = ""
)
HomeFragment.kt
val db = FirebaseF
我希望从firebase防火墙获取数据,并使用数据类来转换toObject()。但是,当对象被初始化时,它不能工作,但是字段没有被设置。
这与非常相似。但我已经使用了建议中的使用数据类的答案,但它仍然不起作用。
数据类
data class DataClass(
var str : String = "default",
var int : Int = 0,
var bool: Boolean = false
)
注意:使用非数据类或更改var名称(在代码和中,数据库)没有任何区别。
实际上,我想使用更复杂的数据/对象,但为了让它首先工作,我剥离了所有其
在kotlin函数中,要获得返回类型,我面临一个问题。
功能是
override suspend fun uploaded_docs_retrival() : ArrayList<String> {
Firebase.firestore.collection("profiles").whereEqualTo("uid", "$uid").get()
.addOnSuccessListener { result ->
for (document in result) {
我在用
implementation 'com.google.firebase:firebase-firestore:21.3.1'
用于在1.3.50版本中用Kotlin测试。
对于读/写测试,我创建了一个简单的数据类:
data class Location(
val uuid: String? = null,
val name: String? = null
)
它运行得很好很顺利,就像预期的那样。
但是,深入一点用Kotlin的密封类扩展数据类会导致序列化中的问题:
data class Location(
val uuid: String? =
在Firebase实时数据库中,支持使用GenericTypeIndicator对对象进行反序列化。有人能解释一下如何用Firestore做同样的事情吗?
我有一个文档快照,我想把它转换成一个参数化的POJO。
这是当我尝试这样做时它抛出的错误
java.lang.RuntimeException: Could not deserialize object. Class com.thesportsbeing.thesportsbeing.screens.festadmin.eventslist.eventadmin.scoring.MatchScore has generic type par
我在我的应用程序中使用Firestore,在调试版本中,一切都像预期的那样工作。但是,当使用发布版本时,我得到这个错误:
java.lang.RuntimeException: No properties to serialize found on class com.*.*.h.g.f
at com.google.firebase.firestore.n0.j$a.<init>(Unknown Source:498)
at com.google.firebase.firestore.n0.j.z(Unknown Source:12)
at com.goog
我在firebase中有这种类型的数组,但是如何获取它并在kotlin中使用,我可以获得作为字符串,但是如何将它作为data class来获取。
像这样
data class Comment(
val uid: String,
val comment: String,
val stamp: Timestamp
)
下面是获取字符串的代码
var text by remember { mutableStateOf("loading...") }
FirebaseFirestore.getInstance().collection("MyApp
在Firestore中存储多态对象的最佳方式是什么? 例如:假设一个"base“对象,其他三个对象继承自该对象。我考虑将特定的对象全部存储在同一个集合中。例如,firestore是否可以理解字段索引的查询,这些查询可能存在于一个文档中,而不存在于另一个文档中? 结构是: BaseObject
A extends BaseObject
B extends BaseObject
C extends BaseObject 因此,我认为将A、B和C存储在同一个集合中,并根据超类中常见的"type“属性进行类型转换…… 所以在查询的时候,我想简单地知道类型和类型转换。但是,我真的不知道
我在Kotlin是个新手。我有一个数据类,其中包含名为testModel的图像urls。我需要使用该代码将数据从firebase添加到模型: 下面是我的数据模型:class testModel(val imageLinks: List<String>) private val dbRef = FirebaseDatabase.getInstance().reference.child("categories").child("1").child("top")
fun readDataFromFirebase(){
db
我已经将包添加到我的新flutter项目中,所以我创建了一个新的flutter项目,用于测试Firebase包。
在"package“之后得到了这个错误,并启动了该项目。
Launching lib\main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...
Resolving dependencies...
Gradle task 'assembleDebug'...
registerResGeneratingTask is deprecated, use registe
在运行时,在颤振中面对这个错误。应用程序成功地连接到了防火墙。在运行过程中也花费了太多的时间,我使用的是android工作室。
//依赖性
dependencies:
flutter:
sdk: flutter
cloud_firestore: ^0.13.0+1
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':cloud_firestore:extractDebugAnnotations'.
> Could not reso
我有一个Contact模型,它包含不同的属性和属性列表。现在,我想将它们存储在Firestore中,但使用列表作为相应文档的子集合。
Contact模型的一个最小示例如下(注意列表被排除在地图之外):
class Contact(private val map: MutableMap<String, Any?>){
var nameDisplay:String? by map
var nickname:String? by map
var organisation:String? by map
val phones:ArrayList<Phon
我有kotlin数据类
data class Client(
val name: String = "",
val email: String = "",
val phone: String ="") {
constructor():this("","","")}
我已经将数据填充到类中,但是我想不知道如何将文档id输入数据类,而不必在文档本身中设置它。这个是可能的吗?
我有这样的Java POJO类:
class Topic {
@SerializedName("id")
long id;
@SerializedName("name")
String name;
}
我有一个这样的Kotlin数据类
data class Topic(val id: Long, val name: String)
如何向kotlin data class的任何变量提供json key,就像java变量中的@SerializedName注释一样?