public data class BluePrint (
JsonProperty("id") val id : Int,
JsonProperty("name") val name : String,
JsonProperty("content") val content : String) {
}
and i get this error when trying to serialize it using jackson:
java.lang.IllegalArgumentException: Conflicting getter definitions for property "id": qs.contracts.BluePrint#getId(0 params) vs qs.contracts.BluePrint#component1(0 params)
when i remove the annotations it works or when i remove the data from the class definition it works. this is because kotlin puts the jackson anotation on the component1 function too.
how can we use the dataclass with jackson annotations?
please help. thanks.
The effect you described is a bug. Auto-generated component functions should not be annotated. I reported it.
In general this is a tricky usecase because we are yet to come to a final decision on what annotating a property means. In current version it results in backing field being annotated (but not getter or setter).
The answer would be: use some workaround until the bug is fixed. Here is an ugly one:
data class BluePrint(private val _id: Int) {
val id: Int [JsonProperty("id")] get() = _id
}
Tomer, you do not need any annotations. Jackson has a Kotlin module to support data classes directly (and other classes that cannot have a default constructor):