@NotNull validation on constructor arguments doesnt work

Viewed 1939

I have class with final fields. When I validate my fields on the constructor - there is a NullPointerException. I use javax.validation.constraints.NotNull. It is occurs only when I validate fields in the constructor. When I do it earlier - it`s work. Do you know why? //It is working good

public final class User { 

@NotNull private final String name; 
@NotNull private final List<Notes> notes; 

@JsonCreator public User(String name, List<Notes> notes){ 
this.name = name; 
this.notes = notes }



//It isn`t working, NPException 
public final class User { 

private final String name; 
private final List<Notes> notes; 

@JsonCreator 
public User(@NotNull String name, @NotNull List<Notes> notes){ 
this.name = name; 
this.notes = notes }
0 Answers
Related