使用带有连字符的 @SerializedName 不起作用

bar*_*633 3 android kotlin json-serialization ktor ktor-client

我正在尝试将此 JSON 响应反序列化为一个对象,并且我的一个键上有一个连字符。不幸的是,Kotlin 不支持变量名称中的连字符,这就是我使用 @SerializedName() 但它现在仍然有效的原因。有什么线索可以解释为什么吗?

JSON 响应

[
    {
        "dateCreated": "07-22-2021",
        "comments": "Comment",
        "vehicle_type": "Sedan",
        "name": "Leagacy Nissan Template",
        "template-type": "", //this is giving me the problem
        "template_uses_type": "Both"
        ...
    }
]
Run Code Online (Sandbox Code Playgroud)

我的对象:

@Serializable
data class SpinDataResponse(
    val dateCreated:String,
    val comments: String,
    val vehicle_type:String,
    val name:String,
    @SerializedName("template-type") val template_type:String,
    val template_uses_type:String,
    ...
)
Run Code Online (Sandbox Code Playgroud)

错误:

I/System.out:错误:偏移量 120 处出现意外的 JSON 令牌:遇到未知密钥“模板类型”。在“Json {}”构建器中使用“ignoreUnknownKeys = true”来忽略未知键。JSON 输入:.....“名称”:“Nissan PathFinder”,“模板类型”:“”,“template_.....

我不想忽略未知的密钥,因为我实际上需要它。