首页 > 解决方案 > 是否可以在没有 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 应用程序对于未使用的功能来说是一个很大的开销百分比:)

标签: javaresteasyquarkus

解决方案


您缺少一个额外的依赖项,这是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在下面的评论中指定此选项不适用于本机图像


推荐阅读