I am trying to add validation to my DTO if a particular field is missing or the field is blank then an error should be thrown that a particular field is missing or is not present I am using object mapper to map the fields eg
StudentDto studentDto = mapper.convertValue(jsonObject, StudentDto.class);
DTO class
@Data
@FieldDefaults(level = AccessLevel.PRIVATE)
public class StudentDto {
@NotNull(message = "FirstName is null")
@NotBlank(message = "FirstName is missing")
String firstName;
@NotNull(message = "LastName is null")
@NotBlank(message = "LastName is missing")
String lastName;
}
I will receive all the values from jsonObject and then I will map those values to DTO. An error should be thrown when a particular field is missing or is blank.But currently I don't receive error the program executes successfully what can I do the achieve this