0

I started a basic Spring Boot banking application. Basically, POST need mandatory fields for amount and user. I have added @Valid and @NotEmpty, but using these, empty POST goes through as well.

clientController.java

@RestController
public class clientController {

@Autowired
private clientRepo repo;

@PostMapping("/saveClient")
ResponseEntity<String> saveClient(@Valid @RequestBody Client client){
    repo.save(client);
    return ResponseEntity.ok("Client saved.");
}
@GetMapping("/payments")
List<Client> getAll(){
    return repo.findAll();
}

}

Client.java

@Entity
@Data
public class Client {
@Id
@GeneratedValue
private UUID id = UUID.randomUUID() ;

@DecimalMin("1.0")
private double amount;
@NotNull
private String debtorIban;

private LocalDateTime createdAt = LocalDateTime.now(ZoneOffset.UTC).withNano(0);
}
Viktor Jovanovski
  • 1,513
  • 10
  • 26
  • 1
    Does this answer your question? [Spring Boot - Validations stopped working after upgrade from 2.2.5 to 2.3.0](https://stackoverflow.com/questions/61959918/spring-boot-validations-stopped-working-after-upgrade-from-2-2-5-to-2-3-0) – Panagiotis Bougioukos May 10 '21 at 10:43
  • Maybe? Before trying this, wrong inputs went through. Now nothing goes throug, I get Internal Server Error 500. I'm not sure if I have a problem somewhere with my code or there is some other problem. – Cardiovascular May 10 '21 at 11:57

1 Answers1

0

I have found the problem. By changing double to BigDecimal, the validation goes through.