Kotlin并没有采取“是"的态度.作为json键的开始 [英] Kotlin is not taking "is" as start of json key

查看:67
本文介绍了Kotlin并没有采取“是"的态度.作为json键的开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在经历一个非常奇怪的小问题.我有一个用于Json解析的数据类.该数据类(Json)具有一个属性

I am going through very strange and small issue. I have one data class which I am using for Json parsing. That data class (Json) has one attribute

val isExpired:布尔值

val isExpired: Boolean

,但是在创建响应后,它不会以 isExpired 作为键.始终将其更改为已过期.

but after response creation its not taking isExpired as key. It's always changing it to expried.

"expired": false

推荐答案

您是否正在使用Jackson进行序列化?如果是这样,那么答案通常是您需要使用@JsonProperty("isExpired")注释属性.但是,在Boolean属性的特定情况下,并非完全如此,如

Are you using Jackson to do the serialization? If so, then the answer would normally be that you need to annotate the property with @JsonProperty("isExpired"). However in the specific case of Boolean properties it's not quite that, as discussed here. So actually what you need to do here is as follows:

data class MyClass(@get:JsonProperty("isExpired") val isExpired: Boolean)

这篇关于Kotlin并没有采取“是"的态度.作为json键的开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆