Tag Archives: XXX is not valid

[How to Solve] Java nested object @validated is not valid

1. Controller layer

@ApiOperation(value = "port")
    @PostMapping("/ygbx/regular")
    public Long regular(@Validated @RequestBody OrderCheckRegularVO vo) {
        return orderCheckService.saveRegular(vo);
    }

2. Main Vo

Solution: add @valid to the VO declaration inside the main vo

@Data
@ApiModel(description = "VO")
public class OrderCheckRegularVO extends OrderCheckBaseVO {

    @NotNull
    @Valid
    private ProductYgbxRegularVO price;

    @NotNull
    @Valid
    private OrderCheckRegularPolicyInfoVO policyInfo;

    @NotNull
    @Valid
    private OrderCheckChargeInfoVO chargeInfo;

    @NotNull
    @Valid
    private OrderCheckBenefitTotalVO benefitInfo;

    @NotEmpty
    @Valid
    private List<OrderCheckKindVO> kindList;


}