0

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 @Validation is never triggered. What am I doing wrong, or is even possible to do it this way?

Alchnemesis
  • 479
  • 8
  • 23
  • Although you've annotated the type with `@Controller`, you're not actually using it as a controller, you're using it as a regular bean. There's no validation logic applied to that. – Sotirios Delimanolis May 13 '16 at 18:40
  • Thanks! Haven't do a good search before posting this question, apologies. Looking at the original question now. – Alchnemesis May 13 '16 at 19:05

0 Answers0