当我使用
JsonProperty
时,它会导致问题
java.lang.IllegalStateException: Conflicting/ambiguous property name definitions (implicit name 'ndc'): found multiple explicit names: [ndc, isNdc], but also implicit accessor: [method com.himshers.supplychain.inventoryapi.model.LotItem#getNdc()][visible=true,ignore=false,explicitName=false]
我的数据类如下,我也想在序列化上有
isNdc
字段。
data class LotItem(
@JsonProperty("lotId") val lotId: String? = null,
@JsonProperty("ndc") val ndc: String? = null,
) {
@JsonProperty("isNdc")
fun isNdc(): Boolean {
return ndc != null
}
}
目前在 Kotlin:2.0.0、Jackson:2.17.1、Java 21 上。 这曾经适用于 Kotlin:1.9.20,Jackson:2.16.0,Java:13。
添加
jackson-module-kotlin
依赖项解决了问题
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
</dependency>