The validation rules for inner field from Lists are not forwarded.
The NotBlank validation is expected for all fields, but it does not work for "location.zip" and "location.city" inside the addresses array.
I am using the Rest API via /service/<site>/<app>/rest/datasource/personAddress/
I have tried adding validation direkty in the the datasource.xml to the field or programatically in the DataProvider but none seem to work
example data model:
public class Person { private Integer id; @NotBlank private String name; @NotBlank private String lastname; @Valid private List<Address> addresses = new ArrayList<>(); } public class Address { @NotBlank private String addressId = "42"; @Valid private Location location = new Location(); } public class Location { @NotBlank private String zip = "12345"; @NotBlank private String city = "Berlin"; }
example datasource.xml
<datasource id="personAddress"> <config> <meta-data bindClass="de.testproject.Person"> <field name="lastname" type="text" /> <field name="name" type="text" /> <field name="addresses" type="list:object" binding="addresses"> <field name="addresses[]" type="object" binding="addresses[]"> <field name="addressId" type="text" /> <field name="location.zip" type="text" /> <field name="location.city" type="text" /> </field> </field> </meta-data> </config> <bean id="personDataSource"> <option name="person" id="1" /> </bean> </datasource> return foo; }
Log trying to add validation
DefaultValidationProvider: Found constraint(s) for path addresses on type class de.testproject.Person: [] DefaultValidationProvider: Adding validation data for field addresses[] for class class de.testproject.Person DefaultValidationProvider: Found constraint(s) for path addresses[] on type class de.testproject.Person: [] DefaultValidationProvider: Adding validation data for field addresses[].addressId for class class de.testproject.Person DefaultValidationProvider: Found constraint(s) for path addresses[].addressId on type class de.testproject.Person: [ConstraintDescriptorImpl{annotation=o.a.a.NotBlank, payloads=[], hasComposingConstraints=false, isReportAsSingleInvalidConstraint=true, constraintLocationKind=FIELD, definedOn=DEFINED_LOCALLY, groups=[interface javax.validation.groups.Default], attributes={groups=[Ljava.lang.Class;@58469429, message={validation.notNull}, payload=[Ljava.lang.Class;@58e50dcc}, constraintType=GENERIC, valueUnwrapping=DEFAULT}] DefaultValidationProvider: Adding validation data for field location.zip for class class de.testproject.Person DefaultValidationProvider: Adding validation data for field addresses[].location.city for class class de.testproject.Person