0

currently I'm struggling with a FieldDescriptor which seem not to "see" all validation constraints. Following scenario:

I have an Dto similar to:

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ExampleDto {

    @NotNull
    @Valid
    private GeoCoordinates coordinate;

    @Min(value = 0)
    @Max(value = 100)
    private BigDecimal workingProperty = BigDecimal.valueOf(0);

//...

And a class GeoCoordinates like this:

@Getter
@NoArgsConstructor
public class GeoCoordinates {

    @NotNull
    @Max(value = 180)
    private Double latitude;

//...

The constraints on the "workingProperty" are properly found on the FieldDescriptor: enter image description here

The opposite is happening on the FieldDescriptor of the coordinate: enter image description here

Following the documentation https://docs.spring.io/spring-restdocs/docs/current/reference/html5/#documenting-your-api-constraints-finding I don't see the issue why the constraint on one field is found and not on the other. Especially as the Validator is validating everything correctly.

hilbert
  • 266
  • 4
  • 15
  • A FieldDescriptor itself doesn't know anything about constraints. You have to discover the constraints and then add them to the descriptor. Without knowing how you have discovered the constraints and configured your field descriptors with them, it's not clear what the problem might be. Can you update your question with a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example)? – Andy Wilkinson Nov 13 '20 at 14:12
  • Thank you @AndyWilkinson for requesting a minimal reproducible example. By creating it I was able to find and fix my failure. – hilbert Nov 18 '20 at 07:22

1 Answers1

1

After some research I found the reason for the issue in a custom ValidatorConstraintResolver. It was only investigating the top level constraints and i had to dive deeper by using reflections.

hilbert
  • 266
  • 4
  • 15