java - 在 JAX-RS 1.1.0 中处理未知属性
问题描述
我坚持使用 JAX-RS 1.1.0 来使用 REST,而我正在使用 javax.validation 1.1.0.FINAL。
当消费者在 JSON 中发送未知属性时,他们会收到UnrecognizedPropertyException
500 错误代码和大量 yadi yadi..
我还没有找到一种方法来捕获这个异常并发回我选择的东西(例如 400 错误)
签名如下所示:
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response storeDocument(DokumentData dokumentData)
在这个旧版本的 JAX-RS 中有没有办法很好地处理这个异常?在 2.0 版中有,@JsonIgnoreProperties(ignoreUnknown = true)
但我不能使用它。
堆栈跟踪:
[ERROR ] An unhandled exception occurred which will be propagated to the
container.
Unrecognized field "personnummer1" (Class
se.skandia.ad14.valueobjects.DokumentData), not marked as ignorable
at [Source: com.ibm.ws.webcontainer.srt.SRTInputStream@46611da2; line: 6,
column: 23] (through reference chain:
se.skandia.ad14.valueobjects.DokumentData["personnummer1"])
[ERROR ] SRVE0777E: Exception thrown by application class
'org.apache.wink.server.internal.RequestProcessor.handleRequest:195'
javax.servlet.ServletException:
org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized
field "personnummer1" (Class se.skandia.ad14.valueobjects.DokumentData), not
marked as ignorable
at [Source: com.ibm.ws.webcontainer.srt.SRTInputStream@46611da2; line: 6,
column: 23] (through reference chain:
se.skandia.ad14.valueobjects.DokumentData["personnummer1"])
at org.apache.wink.server.internal.RequestProcessor.handleRequest(RequestProcessor.java:195)
at [internal classes]
Caused by: org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "personnummer1" (Class
se.skandia.ad14.valueobjects.DokumentData), not marked as ignorable
at [Source: com.ibm.ws.webcontainer.srt.SRTInputStream@46611da2; line: 6, column: 23] (through reference chain: se.skandia.ad14.valueobjects.DokumentData["personnummer1"])
at org.codehaus.jackson.map.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:53)
... 1 more
解决方案
推荐阅读
- python-3.x - 类型错误:元组索引必须是整数或切片,而不是 str --python flask
- laravel - Laravel 雄辩的 whereHas 第一次约会在特定日期之后
- clojure - Bidi 发布请求被禁止但获取请求有效
- string - 如何在 FOR 循环中对 Python Pandas 列表中的元素执行字符串更改
- swift - ARKit - 沿特定方向调整对象大小
- youtube-api - YouTube 数据 API - 频道 ID 在 2 月 28 日一夜之间发生了变化
- excel - getElementBy(Value?) 需要检查元素是否被点击打开(true) 或关闭(false)
- javascript - 添加新项目时vsCode刷新树
- python - 有没有办法使用 .txt 作为输入?
- oracle-sqldeveloper - 在 Oracle SQL Developer 中遇到 GUI 延迟