I'm a C# developer who has recently been thrown onto a Java team at my company. We use Jakarta Bean Validation in our spring-based microservices, and I've been trying to read through the specification to get a better understanding of the framework. However, I've noticed what I believe to be an inconsistency in the documentation.
When reading through the Jakarta Bean Validation specification (https://beanvalidation.org/2.0/spec/), it states that "the Jakarta Bean Validation specification defines a framework for declaring constraints on JavaBean classes, fields and properties.
Later on in the specification, it uses the following class as an example JavaBean to demonstrate the validation annotations provided by the framework.
public class Address {
@NotNull @Size(max=30)
private String addressline1;
@Size(max=30)
private String addressline2;
private String zipCode;
private String city;
public String getAddressline1() {
return addressline1;
}
public void setAddressline1(String addressline1) {
this.addressline1 = addressline1;
}
public String getAddressline2() {
return addressline2;
}
public void setAddressline2(String addressline2) {
this.addressline2 = addressline2;
}
public String getZipCode() {
return zipCode;
}
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
@Size(max=30) @NotNull
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
}
However, based on what I have read online, this class does not fit the definition of a JavaBean, since it does not implement the Serializable interface.
In the very next paragraph (https://beanvalidation.org/2.0/spec/#constraintdeclarationvalidationprocess-requirements), the specification then states that the only real requirement of classes to be validated is that they follow the getter/setter convention of the JavaBeans spec.
So, if the specification is named Java Bean Validation, and they explicitly state the goal is to define constraints on JavaBean classes, then why does the example and constraint requirements not adhere to the need for serializability?
Are JavaBeans no longer required to be serializable or is this documentation actually inconsistent?
I realize I'm probably overthinking this, but as someone new to the Java ecosystem, I'd like to make sure I have a strong understanding of fundamentals like this.