79243609

Date: 2024-12-02 10:04:45
Score: 2
Natty:
Report link

The @Valid annotation plays vital role in validating DTO's / Value Objects where there are multiple attributes inside them that may need validations like @notNull, @length, @max etc.,. However as String doesnt have such attributes and it is a library class, you wont be able to specify what validations to perform on its internal attributes.

Solution 1: You can ignore trying to use @Valid over a primitive class like String

Solution 2: You can create a custom annotation based validator in case if you have any specific validations to perform.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • User mentioned (1): @Valid
  • User mentioned (0): @notNull
  • User mentioned (0): @length
  • User mentioned (0): @max
  • User mentioned (0): @Valid
  • Low reputation (1):
Posted by: Vamsi Krrish