-
Notifications
You must be signed in to change notification settings - Fork 38.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jakarta validation field constraints in superclass are ignored in native image #31552
Comments
This is expected issue. @AssertTrue is a method level constraint. Method level constraint are define at method level and apply only to specific class in which they are declared. By default,they are not inherited by child class. You solution will work but it may not be stander way to handle method-level constraints in a parent class are triggered when validating in child class. I will mention some way that you can try :
public interface ResquestValidationGroup{
} @GroupSequence({Default.class,ResquestValidationGroup.class})
@NoArgsConstructor
public class RequestDTO {
@NotNull
private String name;
@NotNull
private LocalDate startDate;
@NotNull
private LocalDate endDate;
@JsonIgnore
@AssertTrue(message = "Range not valid")
public boolean isRangeValid()
{
if(getEndDate()==null) return true;
if(getStartDate()==null) return true;
if (getStartDate().isEqual(getEndDate())) return true;
return getEndDate().isAfter(getStartDate());
}
} @GroupSequence({Default.class,ResquestValidationGroup.class})
@EqualsAndHashCode(callSuper = true)
@JsonIgnoreProperties("code")
public class RequestExtensionDTO extends RequestDTO{
public RequestExtensionDTO(){
super();
}
}
@EqualsAndHashCode(callSuper = true)
@JsonIgnoreProperties("code")
public class RequestExtensionDTO extends RequestDTO{
public RequestExtensionDTO(){
super();
}
@AssertTrue(message = "Range not valid")
@Override
public boolean isRangeValid()
{
return super.isRangeValid();
}
} Node : Use custom validation group is more acceptable . (Please Correct me if i am wrong. ) |
@nexus061 Yes please share your demo/repro and confirm that the issue happens only while running the application compiled as a native image, while behaving as expected with the JVM. |
I confirm that it only occurs with native compilation, with the classic start of the jar it works. I have a demo project that I tested with swagger, if you give me some time I will also create the test suite |
Can't reproduce for now
@nexus061 I can't reproduce with sdeleuze/spring-aot-smoke-tests@gh-31552, please provide a reproducer. |
i have done this repo https://github.com/nexus061/test_spring, is possible run native test with docker image of grallvm? @sdeleuze have done a fix for test case |
I can indeed reproduce with the repo you provided by running |
@sdeleuze thanks for fix, when will the next version be released? |
You're welcome, you can find the date by clicking on the related milestone. |
Affects: Spring 6.1.5 with Spring Boot 3.1.5
I have this class
and a subclass:
When I use the subclass with
@Valid
in a POST method of controller...... the annotations defined in the parent class do not trigger;
@AssertTrue
defined on the method instead triggers.The following metadata is produced:
In order to overcome the problem I have to create a specific hint for the parent class:
This way the constraints are all triggered.
Is this behavior correct?
If you need it, I have a demo.
The text was updated successfully, but these errors were encountered: