Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Moshi:平台类BigDecimal的问题_Android_Json_Moshi - Fatal编程技术网

Android Moshi:平台类BigDecimal的问题

Android Moshi:平台类BigDecimal的问题,android,json,moshi,Android,Json,Moshi,我有一门课: @JsonClass(generateAdapter = true) data class DayAveragePriceModel( val asset: Asset, val value: BigDecimal ) 其中,Asset是我拥有的自定义类。我试图使用Moshi,但出现以下错误: 原因:java.lang.IllegalArgumentException:平台类java.math.BigDecimal(无注释)要求注册显式JsonAdapter 我怎

我有一门课:

@JsonClass(generateAdapter = true)
data class DayAveragePriceModel(
    val asset: Asset,
    val value: BigDecimal
)
其中,
Asset
是我拥有的自定义类。我试图使用
Moshi
,但出现以下错误:

原因:java.lang.IllegalArgumentException:平台类java.math.BigDecimal(无注释)要求注册显式JsonAdapter

我怎样才能解决这个问题?我试过了

        return Moshi.Builder()
            .add(KotlinJsonAdapterFactory())
            .add(Object::class.java)
            .build()
    }
但它正在崩溃


提前多谢

例外情况是,这是一种平台类型,您需要使用其公共API对其进行编码和解码

object BigDecimalAdapter {
  @FromJson fun fromJson(string: String) = BigDecimal(string)

  @ToJson fun toJson(value: BigDecimal) = value.toString()
}

return Moshi.Builder()
    .add(BigDecimalAdapter)
    .add(KotlinJsonAdapterFactory())
    .build()

我正试图按照您的示例为ULong和UByte添加适配器,但在将它们各自的适配器添加到构建器后,仍然会出现错误。请查看我的问题