android - 如何观察 Moshi Kotlin 中的意外响应?
问题描述
当 api 的 JSON 响应发送除 STATIONARYTOOL 或 STATIONARYTOOL 以外的其他工具时,我的应用程序崩溃了,我如何观察 Moshi 中的后端是否发送了一些额外的工具。我尝试使用“.withDefaultValue”,但没有奏效。我应该如何实现它。(注意我没有列出/知道,这样应用程序就不会抛出错误?
val moshi: Moshi = Moshi.Builder()
.add(PolymorphicAdapters.tool)
.build()
object PolymorphicAdapters {
val tool: PolymorphicJsonAdapterFactory<Tool> =
PolymorphicJsonAdapterFactory.of(Tool::class.java, StaticConstants.TYPE)
.withSubtype(
Tool.STATIONARYTOOL::class.java,
Tool.STATIONARYTOOL.name
)
}
sealed class Tool(
@Json(name = StaticConstants.TYPE) val type: Tooltype,
var position: Long = 0
) {
@JsonClass(generateAdapter = true)
data class STATIONARYTOOL(
val `data`: List<GenericDataCard.StationaryDataCard> = listOf(),
val style: String = ""
) :
Tool(Tool.STATIONARYTOOL)
}
解决方案
推荐阅读
- r - 有没有办法在不改变美学的其他属性的情况下改变 ggplot 图例的中断?
- python - 使用 GCC 编译 Cython 生成的 C 文件
- next.js - 使用 nextjs 将当前构建时间嵌入到 human.txt 文件中
- plotly - 使用多个加密货币折线图的下拉菜单
- python - Using a "getter" as a default value of a python function
- javascript - 如何使用 Wolfram 语言中的 JavaScript 在下拉列表中选择一个值?
- twilio - 如何使用 Twilio API 创建转发来电的 Twilio 函数(或任何其他 Twilio 内置服务)?
- javascript - 悬停在样式组件中不起作用,其他样式工作正常
- python - 叶热图意外加权结果
- python - ValueError:在编写一个非常基本的密码管理器时,没有足够的值来解压缩 python3 中的错误