I have the following REST API:
@ResponseBody
@PostMapping(path = "/configureSegment")
public ResponseEntity<ResultData> configureSegment(@RequestParam() String segment,
@RequestBody @Valid CloudSegmentConfig segmentConfig
) {
CloudSegmentConfig:
@JsonProperty(value="txConfig", required = true)
@NotNull(message="Please provide a valid txConfig")
TelemetryConfig telemetryConfig;
@JsonProperty(value="rxConfig")
ExternalSourcePpdkConfig externalSourcePpdkConfig = new ExternalSourcePpdkConfig(true);
TelemetryConfig:
public class TelemetryConfig {
static Gson gson = new Gson();
@JsonProperty(value="location", required = true)
@Valid
@NotNull(message="Please provide a valid location")
Location location;
@Valid
@JsonProperty(value="isEnabled", required = true)
@NotNull(message="Please provide a valid isEnabled")
Boolean isEnabled;
Location:
static public enum Location {
US("usa"),
EU("europe"),
CANADA("canada"),
ASIA("asia");
private String name;
private Location(String s) {
this.name = s;
}
private String getName() {
return this.name;
}
}
When I'm trying to send the following JSON:
{
"txConfig": {
"location": "asdsad"
}
}
The API return empty response 400 bad request, while I expect it to validate the location to be one of the ENUMs of the class. I also expect it to validate the isEnable parameter while it doesn't although I added all possible annotation to it..
Any idea?