如何在Android的Firestore中存储bigdecimal

时间:2018-07-17 04:51:05

标签: java android google-cloud-firestore bigdecimal

我正在尝试使用Android Studio将对象插入Firestore,它会显示错误消息:

chrome.devtools.panels.create("My devtools extension",
"logo.png",
"page.html",
function(panel) {
    panel.onShown.addListener(function(event) {
        ...
    });

    panel.onHidden.addListener(function(event) {
        ...
    });

    panel.onSearch.addListener(function(event) {
        <your code here>
    });
});

error message

如何将BigDecimal插入Firestore?

2 个答案:

答案 0 :(得分:0)

检查Firestore的supported types。如果您需要其他任何内容,请转换为受支持的类型,然后在阅读时转换回去。通常,您将String用于BigDecimal。如果需要比较,请零填充至理论最大值,或将其存储为Double

答案 1 :(得分:0)

您可以执行以下操作(在Kotlin中):

class Model() {

    @get:PropertyName("value") 
    @set:PropertyName("value")
    var firestoreValue: String = "0"

    var value: BigDecimal
        @Exclude get() = firestoreValue.toBigDecimal()
        @Exclude set(value) { firestoreValue = value.toPlainString() }
}

到目前为止,还没有找到更好的解决方案。如果可以为不受支持的类型实现转换器(例如Gson的TypeAdapters),那就太好了。