Don't validate if field if null


#1

Hi

I am using hibernate validation to validate a brazillian number for companies, called CNPJ

	@CNPJ
	@Column(nullable = true, length = 18, unique = true)
	private String cnpj;

But in my form this field is not required.

But and I try to save a register with CNPJ field null, I got a NotValidException.

How do I not validate if this field is null ?


#2

Hi,

Are you sure the exception is coming from Hibernate Validator? Because we do accept null values: https://github.com/hibernate/hibernate-validator/blob/master/engine/src/main/java/org/hibernate/validator/internal/constraintvalidators/hv/br/CNPJValidator.java#L53 .


#3

I think so…

And out front-end is sending CNPJ field with “”, and not “null”. I think this is the problem…

Now I am trying to send “null” instead “”