- I have a kotlin data class, having a parameterized constructor, and a method which derives its output based on a property.
- I have annotated this method with @JsonProperty so that its derived output can also be serialized to output JSON, as that was a requirement to me.
- Now the issue arises when I try to deserialize this JSON, and it doesn't find any field for the derivedProp
Cannot construct instance of
MyDataClass
, problem: Should never callset()
on setterless property ('derivedProp')
@JsonIgnoreProperties(ignoreUnknown = false)
data class MyDataClass(
val boolProp: Boolean = true,
val dataProp: DataProp = DataProp(),
val mainProp: String? = null
) : Serializable {
@JsonProperty
@Suppress("unused")
fun derivedProp(): List =
someLogicOnMainProp(mainProp)
}