0
import javax.validation.constraints.Pattern;

public class Data {

    Details details ;
}
public class Details {

    @Pattern(regexp = "^[//a-zA-Z0-9]+$", message = "yyyyy")
    private String Id;
}

In controller layer

@RequestMapping(value = "/xyz", method = RequestMethod.POST)
public Object create(@Valid @RequestBody Data policy, HttpServletRequest request,   
                                                                        HttpServletResponse response){
}

I need the validations that is present in Details class . It is a sub-class of Data. In controller layer, i have given RequestBody Data and @valid annotation is there I am trying from postman , but not able to throw the @Pattern validation.

Swaraj
  • 9
  • 2
  • 1
    Your question is misleading, `Details` is not subclass of `Data`, `Data` is composed of `Details` (you have composition, not inheritance here). Going by memory, you need to add `@Valid` or `@Validated`, some annotation among those lines, on the details field in `Data` class. – Chaosfire Mar 24 '23 at 08:40

0 Answers0