I'm unable to apply the Jackson's @JsonValue
annotation on the value parameter of enum class:
enum class CancellationReason(@JsonValue val code: String) {
CUSTOMER_RESIGNED("20"),
ERRORS_IN_FOO("21"),
ERRORS_IN_BAR("24");
}
The error message states: This annotation in not applicable to target 'value parameter'
. What's the problem?
You can upgrade jackson-module-kotlin
to version 2.9.0, and the error will be gone, because the @JsonValue
annotation gets a target FIELD
in that version.
Alternatively, fix that by specifying the annotation use-site target by adding @get:
:
enum class CancellationReason(@get:JsonValue val code: String) {
CUSTOMER_RESIGNED("20"),
ERRORS_IN_FOO("21"),
ERRORS_IN_BAR("24");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With