hi, is there a way to specify multiple targets for...
# announcements
v
hi, is there a way to specify multiple targets for one annotation? instead of using two annotations @field:JsonProperty("some") @get:JsonProperty("some")
d
You should only need one or the other
You usually select one convention for your serializable data classes (Java beans): field annotations or getter annotations.
v
Thx for reply. I've found an issue with jackson objectMapper
Copy code
open class A(
    @JsonProperty("Field1")
    val field1: String
)

class B(
    @JsonProperty("Field2")
    val field2: String
) : A("hello")

val b = B("world")
println(objectMapper.writeValueAsString(b))
gives me "{"Field2":"world","field1":"hello"}" But if I specify field: and get: target, it fixed an issue. Ok, thanks, I will search why it happened in jackson source code.
d
Well if you never specify
@field:
or `@get:`then it comes a constructor parameter annotation
I also hope you have the Kotlin module for Jackson installed
Copy code
objectMapper.registerModule(KotlinModule())
1
v
Copy code
A::field1.getter.annotations.forEach {
    println(it.annotationClass)
}
prints com.fasterxml.jackson.annotation.JsonProperty
d
Alright!