I have added annotations in the parent class. It is working fine.
But it is not working in the member variables that is declared as another Object type. It is validating:
orderId
from base classreferenceNumber
fromMarchantApplicationRequest
@NotEmpty
annotation atcustomerRequests
field inMerchantApplicationRequest
.
But it is not validating customerRoleType
in CustomerRequest
.
Also, I would like to add @NotBlank
annotation in customerRequests
. But it is not taking this, though it is taking @NotEmpty
annotation.
Class MerchantApplicationRequest
@JsonIngnoreProperties(ignoreUnknown=false)
public class MerchantApplicationRequest extends IomBaseDTO {
@NotEmpty(message="customerRequests is mandatory")
private List<CustomerRequest> customerRequests;
@NotBlank(message="referenceNumber is mandatory")
private String referenceNumber ;
}
Class CustomerRequest
public class CustomerRequest {
@NotBlank(message="customerRoleType is mandatory")
private String customerRoleType ;
}
Controller class
Method where to apply validation:
@PostMapping("/orderDetail")
public void orderDetail(@Valid @RequestBody MerchantApplicationRequest request) {
try {
iOrderService.updateProductDetail(request);
} catch (Exception e) {
// ...
}
}
Here is my JSON payload:
{
"orderId" : 101,
"referenceNumber" : "123",
"customerRequests" : [ {
"customerRoleType" : null
}]
}
I am using in pom.xml
of Spring Boot application:
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>