Gson注释未应用于所有属性

时间:2019-09-11 08:57:59

标签: kotlin gson

我有以下课程正在转换为Json格式:

@RealmClass
open class ContainerContentExchange(currentDeviceVolume: Double? = null) : RealmObject() {
    @SerializedName("Completed")
    var completed: Date? = null

    @SerializedName("WeightDifference")
    var weightDifference: Double? = null
        get() = field.getRoundedValue(3)

    @SerializedName("WeightStartBrut")
    var weightStart: Double? = null
        get() = field.getRoundedValue(3)
        set(value) {
            field = value

            if (completed == null) {
                weightDifference = weightStop?.subtract(field ?: 0.0)
            }
        }

    @SerializedName("WeightStopBrut")
    var weightStop: Double? = null
        get() = field.getRoundedValue(3)
        set(value) {
            field = value

            if (completed == null) {
                weightDifference = field?.subtract(weightStart ?: 0.0)
            }
        }

    @SerializedName("WeightStart")
    var startNettWeight: Double? = null
        get() = field.getRoundedValue(3)

    @SerializedName("WeightStop")
    var stopNettWeight: Double? = null
        get() = field.getRoundedValue(3)
}

问题是由于某些原因,weightStop以外的所有语言都正确地更改为其序列化名称。因此,最后,我的JSON中有weightStopWeightStop

我尝试将weightStop替换为weightStopBrut,但它仍然没有更改为正确的序列化名称。

getRoundedValue是扩展方法

有人知道这可能是什么问题吗?

编辑:这是要转换为JSON的代码:

Gson().toJson(exchange)

exchange是我要序列化的ContainerContentExchange

0 个答案:

没有答案