在Firestore文档中将数组更改命名约定更新为驼峰式

我有一个产品的数组列表,当我使用更新方法将其设置为firestore文档时,尽管我模型中的变量名称为CapWords,变量的命名仍变为驼峰式。这样您就可以在第一个屏幕截图中看到产品的元素是CapWords,但是当我对其进行更新时,它无缘无故变成了驼峰式保护套

override fun onProductClicked(sku: FirebaseProduct) {
skuItems[0].StatusId = 123 //try to update element in array of products
FirestoreHelper.update(skuItems)}

fun update(skuItems: ArrayList<FirebaseProduct>) {
db.collection(Constants.PURCHASE_RECEIPTS).document(1.toString())
.update("Products",skuItems)} //when i updated the array all the object names turned into camle-case

这是产品购买收据的模型类别

class FirebasePR {

constructor()
constructor(
    maxabPurchaseReceiptId: Long,StatusId: Long?,PoId: Long?,ScannedAt: String?,EndedAt: String?,maxabWarehouseId: Long?,maxabDeliveryDate: String?,ReceiverId: Long?,AreaId: Long?,AdminId: Long?,Products: List<FirebaseProduct>?,NumOfRemaining: Long?,NumOfReceived: Long?
) {
    this.MaxabPurchaseReceiptId = maxabPurchaseReceiptId
    this.StatusId = StatusId
    this.PoId = PoId
    this.ScannedAt = ScannedAt
    this.EndedAt = EndedAt
    this.MaxabWarehouseId = maxabWarehouseId
    this.MaxabDeliveryDate = maxabDeliveryDate
    this.ReceiverId = ReceiverId
    this.AreaId = AreaId
    this.AdminId = AdminId
    this.Products = Products
    this.NumOfRemaining = NumOfRemaining
    this.NumOfReceived = NumOfReceived }

var MaxabPurchaseReceiptId: Long? = null
var StatusId: Long? = null
var PoId: Long? = null
var ScannedAt: String? = null
var EndedAt: String? = null
var MaxabWarehouseId: Long? = null
var MaxabDeliveryDate: String? = null
var ReceiverId: Long? = null
var AreaId: Long? = null
var AdminId: Long? = null
var Products: List<FirebaseProduct>? = null
var NumOfRemaining: Long? = null
var NumOfReceived: Long? = null}

firebase产品类是FirebasePR内的列表

class FirebaseProduct {
constructor()
constructor(
    CreatedAt: Timestamp,UpdatedAt: Timestamp,MaxabProductPurchaseReceiptId: Int,MaxabPackingUnitId: Int,MaxabProductId: Int,MaxabBasicUnitCount: Int,IssuedCount: Int,ReceivedCount: Int,ReceivedAt: Timestamp,EndedAt: Timestamp,StatusId: Int,Quality: Boolean,ExpirationDate: Timestamp,ProductCode: String,MaxabBasicUnitId: Int,Palletsnumber: Int,MaxabProductNameAr: String,MaxabPackingUnitNameAr: String,MaxabProductImage: String
) {
    this.CreatedAt = CreatedAt
    this.UpdatedAt = UpdatedAt
    this.MaxabProductPurchaseReceiptId = MaxabProductPurchaseReceiptId
    this.MaxabPackingUnitId = MaxabPackingUnitId
    this.MaxabProductId = MaxabProductId
    this.MaxabBasicUnitCount = MaxabBasicUnitCount
    this.IssuedCount = IssuedCount
    this.ReceivedCount = ReceivedCount
    this.ReceivedAt = ReceivedAt
    this.EndedAt = EndedAt
    this.StatusId = StatusId
    this.Quality = Quality
    this.ExpirationDate = ExpirationDate
    this.ProductCode = ProductCode
    this.MaxabBasicUnitId = MaxabBasicUnitId
    this.Palletsnumber = Palletsnumber
    this.MaxabProductNameAr = MaxabProductNameAr
    this.MaxabPackingUnitNameAr = MaxabPackingUnitNameAr
    this.MaxabProductImage = MaxabProductImage
}

var CreatedAt: Timestamp? = null
var UpdatedAt: Timestamp? = null
var MaxabProductPurchaseReceiptId: Int? = null
var MaxabPackingUnitId: Int? = null
var MaxabProductId: Int? = null
var MaxabBasicUnitCount: Int? = null
var IssuedCount: Int? = null
var ReceivedCount: Int? = null
var ReceivedAt: Timestamp? = null
var EndedAt: Timestamp? = null
var StatusId: Int? = null
var Quality: Boolean = false
var ExpirationDate: Timestamp? = null
var ProductCode: String = ""
var MaxabBasicUnitId: Int = 0
var Palletsnumber: Int = 0
var MaxabProductNameAr: String = ""
var MaxabPackingUnitNameAr: String = ""
var MaxabProductImage: String = ""}

在Firestore文档中将数组更改命名约定更新为驼峰式

在Firestore文档中将数组更改命名约定更新为驼峰式

fjbjj 回答:在Firestore文档中将数组更改命名约定更新为驼峰式

首先,我将指出启动Kotlin类属性不是常规的Kotlin样式。我建议将它们全部更改为驼峰大小写,以更好地符合Android Kotlin style for non-constant names

如果您想更改从Kotlin类属性自动生成的Firestore文档字段的名称,则应在该Kotlin属性上使用@PropertyName批注,以便Firestore SDK知道您想要的字段名称使用。

@PropertyName是更改Firestore SDK写入文档字段的方式的唯一方法。如果无法使用此批注,则必须构建字段和值的映射以改写。您还必须从地图中读取文档数据。

本文链接:https://www.f2er.com/2845493.html

大家都在问