0

I have a DTO class that has a LocalDateTime field in it like the following:

public class MyModel {
    @NotNull(message="This field cannot be null")
    @DateTimeFormat(iso = ISO.DATE_TIME)
    private LocalDateTime startDate;

    ...
}

And I have a Spring MVC Controller that has a Post Mapping like the following:

@PostMapping("/save")
public String save(@Valid MyModel myModel, BindingResult validationResult) {
    if (!validation.hasErrors()) {
        this.myService.save(myModel);
    }
    else {
        ...
        return "myview";
    }
}

Everything works fine, except that if I do not select a date from the User Interface, the "BindingResult" object has

"Property 'startDate' threw exception; nested exception is java.lang.NullPointerException"

instead of my custom validation message.

Furkan
  • 683
  • 2
  • 10
  • 26

0 Answers0