Kotlin Jackson上不尊重JsonProperty名称
我希望在编写对象时使用自定义名称,但它没有打印我在annotation@JsonProperty中定义的内容:Kotlin Jackson上不尊重JsonProperty名称,kotlin,jackson,Kotlin,Jackson,我希望在编写对象时使用自定义名称,但它没有打印我在annotation@JsonProperty中定义的内容: data class Banking( @JsonProperty("personita_id") val clientId: String?, @JsonProperty("contita_id") val accountId: String? ) val mapper = Ob
data class Banking(
@JsonProperty("personita_id")
val clientId: String?,
@JsonProperty("contita_id")
val accountId: String?
)
val mapper = ObjectMapper()
val xpto = mapper.writeValueAsString(Banking("mammamia", "miaccuenta"))
xpto打印:
{"clientId": "mammamia", "accountId": "miaccuenta"}
“我的代码”中缺少什么?您可以在中的
ObjectMapper
上注册KotlinModule
val mapper=ObjectMapper().registerModule(KotlinModule())
或根据使用的版本而定
val mapper = ObjectMapper().registerKotlinModule();