BAEL-5123: Annotation Processor for Hibernate Validator (#11673)
* feat(wip): add Hibernate Validator AP example * chore: change AP version to 6.2.0.Final See https://hibernate.atlassian.net/browse/HV-1868 * revert(style): remove unnecessary formatter See https://github.com/eugenp/tutorials/pull/11673#discussion_r784444016 * fix: remove unauthorised annotation The AP was triggering a compile time error because the annotation @NotBlank is disallowed for the Profile data type. That's why the CI was failing. This customer class is unrelated to the article being written. * fix(style): revert indentation issue See https://github.com/eugenp/tutorials/pull/11673/files#r788146422
This commit is contained in:
@@ -20,7 +20,6 @@ public class Customer {
|
||||
@PositiveOrZero
|
||||
private OptionalInt numberOfOrders;
|
||||
|
||||
@NotBlank
|
||||
private Profile profile;
|
||||
|
||||
public String getName() {
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.baeldung.javaxval.hibernate.validator.ap;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Past;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Message {
|
||||
|
||||
@NotNull(message = "Content cannot be null")
|
||||
private String content;
|
||||
|
||||
private boolean isDelivered;
|
||||
|
||||
private List<@NotBlank String> recipients;
|
||||
|
||||
// uncomment in order to trigger AP annotation detection
|
||||
// The annotation @Past is disallowed for this data type.
|
||||
// @Past
|
||||
private String createdAt;
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public Message(String content, boolean isDelivered, List<@NotBlank String> recipients, String createdAt) {
|
||||
this.content = content;
|
||||
this.isDelivered = isDelivered;
|
||||
this.recipients = recipients;
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
// uncomment in order to trigger AP annotation detection
|
||||
// The annotation @Min is disallowed for the return type of this method.
|
||||
// @Min(3)
|
||||
public boolean broadcast() {
|
||||
// setup a logic
|
||||
// to send to recipients
|
||||
return true;
|
||||
}
|
||||
|
||||
// uncomment in order to trigger AP annotation detection
|
||||
// Void methods may not be annotated with constraint annotations.
|
||||
// @NotNull
|
||||
public void archive() {
|
||||
// archive the message
|
||||
}
|
||||
|
||||
// uncomment in order to trigger AP annotation detection
|
||||
// Constraint annotations must not be specified at methods, which are no valid JavaBeans getter methods.
|
||||
// NOTE: add <arg>-AmethodConstraintsSupported=false</arg> to compiler args before
|
||||
// @AssertTrue
|
||||
public boolean delete() {
|
||||
// delete the message
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public boolean isDelivered() {
|
||||
return isDelivered;
|
||||
}
|
||||
|
||||
public void setDelivered(boolean delivered) {
|
||||
isDelivered = delivered;
|
||||
}
|
||||
|
||||
public List<String> getRecipients() {
|
||||
return recipients;
|
||||
}
|
||||
|
||||
public void setRecipients(List<String> recipients) {
|
||||
this.recipients = recipients;
|
||||
}
|
||||
|
||||
public void setCreatedAt(String createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setName(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public Optional<@Past String> getCreatedAt() {
|
||||
return Optional.ofNullable(createdAt);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user