https://kotlinlang.org logo
#announcements
Title
# announcements
n

Nezteb

07/31/2019, 5:59 PM
Is there an easy way to interop between Kotlin `data class`es and more traditional libs that require Bean/POJO annotations? If I’m using a lib that requires annotations on a POJO/bean as well as normal getters/setters, I’d like to use a
data class
but I don’t think I can apply annotations to those fields.
m

Mark Murphy

07/31/2019, 6:01 PM
annotations on
data
class properties in general can work -- this is from the Android Room documentation:
Copy code
@Entity
data class User(
    @PrimaryKey var id: Int,
    var firstName: String?,
    var lastName: String?
)
so, try
@get:YourAnnotation
or
@field:YourAnnotation
and see if it works
n

Nezteb

07/31/2019, 6:06 PM
Oh neat! I also just found https://www.kotlin.nl/2018/02/06/kotlin-quick-tip-annotation-targets/ which says similar things. Thanks Mark!
👍 2
9 Views