I want to create Spring endpoint for validating Java Object. I tried to implement this example:
https://www.baeldung.com/validation-angularjs-spring-mvc
I tried this:
public class WpfPaymentsDTO {
@NotNull
@Size(min = 4, max = 15)
private String card_holder;
private String card_number;
....
}
End point:
@PostMapping(value = "/payment/{unique_transaction_id}", consumes = { MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<StringResponseDTO> handleWpfMessage(@PathVariable("unique_transaction_id") String unique_transaction_id,
@RequestBody WpfPaymentsDTO transaction, BindingResult result, HttpServletRequest request) throws Exception {
if (result.hasErrors()) {
List<String> errors = result.getAllErrors().stream()
.map(DefaultMessageSourceResolvable::getDefaultMessage)
.collect(Collectors.toList());
return new ResponseEntity<>(errors, HttpStatus.OK);
}
return ResponseEntity.ok(new StringResponseDTO("test"));
}
When use submits Angular form I would like to validate all fields. But currently I get this error: Cannot infer type arguments for ResponseEntity<>
What is the proper wya to implement this?
>`. In the example you posted, `ResponseEntity