Skip to content
Advertisement

Validation issue with javax constraint

In a spring boot application, I have an entity where I put some annotation validation.

@Max(value = 17)
private String currency;

@Max(value = 1)
private String freq;

@Max(value = 2)
private String compliance;
 
@Max(value = 1)
private String payment;

@Max(value = 1)
private String wallet;

@Max(value = 2)
private String cycle;

@Max(value = 24)
private String histoProfil;

@Max(value = 20)
private String idNo;

@Max(value = 2)
private String special;

Value for theses files

freq="M";
compliance="";
currency="";
payment="";
wallet="O";
cycle="19"
histoProfil="";
idNo="Staple Bill";
special="";

I get many error

for freq: must be lower than or equal to 1
for currency: must be lower than or equal to 17
for compliance: must be lower than or equal to 2
for payment: must be lower than or equal to 1
for wallet: must be lower than or equal to 1
for cycle: : must be lower than or equal to 2
for histoProfil: must be lower than or equal to 24
for idNo: must be lower than or equal to 20
for special: must be lower than or equal to 2

Freq have one character, why i get this message? Empty value is lower then 17 for currency..

I don’t understand why this error occur.

Advertisement

Answer

The @Max annotation are validation for these types: BigDecimal, BigInteger, byte, short, int, long, and their respective wrappers.

https://docs.oracle.com/javaee/6/api/javax/validation/constraints/Max.html

Use a different annotation @Length(min, max) if you are trying to validate string length.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement