Disable validation annotation when filtering with Jackson @JsonView

498 views Asked by At

I have the same form that displays more or less fields depending on the user's role. So I use @JsonView to hide/ignore the fields that are not related to the current user's role. But the validation is still enabled and the @NotNull rule is triggered.

@JsonView({View.Admin.class, View.Tech.class})
@NotNull
private String name;

I would like to find a way to enable or disable some validation annotations for example when the user's role is not administrator.

Is it possible to use these view (View.Admin.class / View.Tech.class) as a group for validation please?

1

There are 1 answers

4
mildgrey On

use @JsonIgnore may help you to achieve,because it will ignore the column and validation annotation as well