Describe the bug
Primary constructor is a good feature in kotlin that helps to achieve builder pattern. But bean validator (@NotNull) and @JsonbDateFormat doesn't work in the primary constructor
Expected behavior
Annotations for bean validator and date format should work in the primary constructor as it works in class attributes.
Actual behavior
Annotations are not evaluated.
To Reproduce
@Entity
@Table(name = "tb_financial_commitment")
class FinancialCommitment(
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
var id: Long? = null,
@Column(name = "limit_date")
@NotNull(message = "Limit date must be provided!")
@JsonbDateFormat(value = "dd/MM/yyyy")
var limitDate: LocalDateTime? = null,
var value: Double? = null
)
Environment (please complete the following information):
uname -a or ver: 1.10.3java -version: 15mvnw --version or gradlew --version): maven 3.6.3Additional context
If the property are declared as class property with lateinit it works properly.
/cc @Sanne, @evanchooly, @gsmet
can you expand a little on "not working well?" I think i can probably see what you're talking about just looking at the example but I'd rather not assume in case i'm wrong. I'd hate to waste everyone's time.
they are ignored.
@andfs you probably should use @field or @get kotlin annotations use-site. https://kotlinlang.org/docs/reference/annotations.html#annotation-use-site-targets
This would be my advice, too. Have you had a chance to try it?
Sorry for taking so long and taking your time with this.
You were right. Using @field worked pretty well.
Thanks for your patience answering me :D