1

In code, i call make a request via RestTemplate.exchange like this

ResponseEntity<LocationDataCarrierDTO> response = myRestTemplate.exchange(
            uri,
            HttpMethod.GET,
            request,
            LocationDataCarrierDTO.class);

And the DTO class looks like this

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class LocationDataCarrierDTO {

    @NotNull
    private GpsDTO gpsData;
}

Is the @NotNull-Validation annotation taken into account by exchange? Aka: does the call to exchange throw an exception if gpsData is NULL?

Velulian
  • 313
  • 5
  • 15
  • no, validation annotation will not be taken into account. you can however integrate the validation with RestTemplate, see https://stackoverflow.com/questions/45333587/is-there-a-way-to-integrate-java-bean-validation-api-with-spring-resttemplate – MarcoLucidi Aug 12 '20 at 17:12

1 Answers1

0

@Validated to your service class, @Valid for the method you are calling, then validation will work

Procrastinator
  • 2,526
  • 30
  • 27
  • 36
Raj
  • 1