java - 如何处理 REST 服务的输入枚举字段的验证错误?
问题描述
我有一个 REST 服务,它接受一个包含枚举字段的对象作为输入。当枚举中不存在的值在输入中传递给我时,会自动启动 BAD REQUEST。我试图进入调试以查看在哪里处理错误,但我注意到它并没有真正进入方法。
检索接口:
@POST
@Path("/retrieve")
public Response retrieveValue(@Valid User user);
用户:
public class User(){
String name;
String surname;
CityEnum city;
// getter and setter whith @NotNull annotation
}
城市枚举:
public enum CityEnum(){
LONDON("London"),
LIVERPOOL("Liverpool"),
...
private String city;
}
我需要返回一条错误消息,并且我假设处理将在实现 Retrieve 接口的 RetrieveService 中完成。如何才能做到这一点?我正在使用微配置文件。
解决方案
推荐阅读
- mysql - 如何从db中选择ip?
- angular - 使用 angular-azure-blob-service 时出现 403 错误
- swift - 使用参数以编程方式创建表视图 - swift
- ios - 如何将 GPS 坐标导航到 CameraView
- mongodb - 可以在 mongoDB Shard 集群中进行增量备份吗?没有 opsmanager
- batch-file - 批处理脚本在操作系统和 Winpe 环境中执行时给出不同的输出
- jquery - Material Design Range Slider:可能有 2 个输入/句柄?
- amazon-web-services - 如何监控 aws api 网关上的获取/发布端点?
- java - 使用 javax.ws.rs.client.WebTarget 处理 APPLICATION_OCTET_STREAM
- c++ - 成员函数 LinkedList::deleteNode 不能重新声明