I have a @RestController
which takes portion of posted data and calls another method in some different @Controller
, and I am unable to @Validate that specific passed parameter in called method.
Data that is being posted will always have one section that is the same for every type, and the section that is specific for each type that is being posted.
public class BasicConfig {
private Integer id;
private String title;
private String type;
}
public class Type1Config extends BasicConfig {
@NotNull
private String value;
}
@RestController:
@RequestMapping(value = "/update", method = RequestMethod.PUT)
public void update(@RequestBody byte[] data) throws JsonParseException, JsonMappingException, IOException {
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
BasicConfig bc = objectMapper.readValue(data, BasicConfig.class);
switch (bc.getType()) {
case "TYPE1":
type1Controller.update(objectMapper.readValue(data, Type1Config.class));
break;
}
return null;
}
@Controller:
@Controller
public class Type1Controller {
public void update(@Valid Type1Config data) {
return null;
}
}
So, here update
method in Type1Controller
has been called, but @Valid
ation is never triggered. What am I doing wrong, or is even possible to do it this way?