Ich habe eine einfache Federauflage-Controller, der so aussieht.Spring Controller Enum Anfrage Validierung
@RestController
public class MyController {
@RequestMapping(path = "mapping", method = RequestMethod.POST, produces = {"application/json"})
public MyResponse create(@RequestBody MyModel requestParam
) throws InvalidApplicationSentException, AuthenticationFailedException {
// method body
}
Hier ist die MyModel-Klasse, die als Anforderungsparameter verwendet wird.
public class MyModel {
private RequestType requestType;
// a lot of other properties ..
}
Jetzt, wenn ich versuche, diesen Endpunkt zu nennen einen ungültigen Wert für Request vorbei erhalte ich eine Ausnahme zurück:
org.springframework.http.converter.HttpMessageNotReadableException
Could not read document: Can not construct instance of com.mypackage.RequestType from String value 'UNDEFINED': value not one of declared Enum instance names: [IMPROTANT, NOT_IMPORTANT]
Gibt es eine Möglichkeit, dass der Frühling die Enum auf null gesetzt würde, wenn falscher Wert übergeben und keinen Fehler werfen?
Ich bin mit Feder 4 und ich würde Konfiguration mit Anmerkungen und nicht die XML-Dateien
Das funktioniert, danke – Tomas