Uploaded image for project: 'appNG'
  1. appNG
  2. APPNG-2405

Field-Validation not working for nested fields inside a list of objects

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Done
    • Priority: High
    • Resolution: Done
    • Affects Version/s: 1.22.1
    • Fix Version/s: 1.23.0
    • Component/s: appng-api
    • Labels:

      Description

      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
      

        Attachments

          Activity

            People

            • Assignee:
              mueller.matthias Matthias Müller
              Reporter:
              c.brueckner Christian Brückner
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: