java - 是否可以在没有 RESTEasy 服务器的情况下使用带有 JSON 反序列化的 Quarkus REST 客户端?
问题描述
我有一个小型 Quarkus 应用程序的用例,它必须能够调用 REST 端点,但它本身不应该运行 Web 服务器。
对于以下依赖项,不支持 JSON 反序列化:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jackson</artifactId>
</dependency>
运行应用程序会输出以下日志:
WARN [io.qua.res.com.dep.ResteasyCommonProcessor] (build-11) Quarkus detected the need of REST JSON support but you have not provided the necessary JSON extension for this. You can visit https://quarkus.io/guides/rest-json for more information on how to set one.
...
ERROR [...] ProcessingException while creating reply for journey details request: RESTEASY003145: Unable to find a MessageBodyReader of content-type application/json and type class X.
(警告是根据这张票添加的:https ://github.com/quarkusio/quarkus/issues/4157 )
将配置更改为:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
REST 客户端 Jackson 反序列化工作,但它也启动一个 Web 服务器。
有没有办法在 REST 客户端上支持 Jackson 反序列化,而无需运行 RESTEasy Web 服务器?
选项 1:我可以为此包含特定的依赖项吗?我分别使用了 quarkus-resteasy-jackson 的依赖项,但没有让它工作。
选项 2:quarkus-jackson 依赖项中是否缺少某些内容?我假设应该能够支持 REST 客户端上的 Jackson 序列化,而无需包含完整的 RESTEasy 依赖项?
其他选择?将~10MB RSS 内存添加到~20MB 应用程序对于未使用的功能来说是一个很大的开销百分比:)
解决方案
您缺少一个额外的依赖项,这是resteasy-jackson2-provider
应该工作的库组合:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
</dependency>
PS as Ken在下面的评论中指定此选项不适用于本机图像
推荐阅读
- python - 情节:相同的轴,但自动缩放?
- python - 仅在使用 Python 延迟加载数据后通过迭代刮表?
- swift - 如何通过点击 showMore/showLess 按钮更新 tableViewController 中的约束
- python - 在tensorflow中将所有0值图像像素转换为255
- installation - Aptana 3 软件安装程序找不到 URL
- php - 自定义 Yii2 插件而不触及核心供应商文件夹
- php - PHP - 如果仅包含 HTML 标签或带有 HTML 标签的文本,则检测字符串
- reactjs - 根据 props 更新内部状态(反模式)
- javascript - Javascript:如何从脚本文件中的 html 页面调用函数
- node.js - ElasticSearch 上的 mapper_parsing_exception 错误