Vertx extension: serializing JsonObject and JsonArray

777 views
Skip to first unread message

Thomas SEGISMONT

unread,
Mar 15, 2019, 1:29:40 PM3/15/19
to quark...@googlegroups.com
Hi everyone,

I did some experiments with Quarkus and the Vert.x extension today. Nice work, I was able to inject the Vert.x instance in a JAX-RS resource and use the Vert.x Web Client.

Many Vert.x clients return Vert.x JsonArray or JsonObject results. As a user, if you use this in your web resource response you'll get a "Could not find MessageBodyWriter for response object of type: io.vertx.core.json.JsonObject of media type: application/json" exception.

Implementing custom body writers is pretty straightforward (both JsonArray and JsonObject have toBuffer() methods). How about providing such writers in the Vert.x extension?


I added the body writers to the Vert.x runtime module and, in the deployment module, updated the VertxProcessor#registerBean method so that they get analyzed.

Yet my test still fails with NoMessageBodyWriterFoundFailure. Could you help me understand what's missing?

Thank you,
Thomas

Message has been deleted

Guillaume Smet

unread,
Mar 15, 2019, 7:45:10 PM3/15/19
to tsegi...@gmail.com, Quarkus Development mailing list
Hi Thomas,

Sorry, I missed your message somehow.

I think the reason for your failure is that your providers are not considered by the RESTEasy extension.

I don't know if RESTEasy is supposed to take into account provider beans (if so we need to do some work in the extension) but right now the extension only considers the ones declared in a `javax.ws.rs.ext.Providers` service file.

If you create a service file and declare them there, I think it should work OK (and you can remove them from the `ÀdditionalBeanBuildItem`).

HTH

--
Guillaume

--
You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quarkus-dev...@googlegroups.com.
Visit this group at https://groups.google.com/group/quarkus-dev.
For more options, visit https://groups.google.com/d/optout.

John O'Hara

unread,
Mar 16, 2019, 2:15:04 AM3/16/19
to Guillaume Smet, tsegi...@gmail.com, Quarkus Development mailing list
Hi Thomas,

Do you have have the jsonb dependency in your pom? I normally see these class of errors when that dependency has not be included.

If you do not have the dependency, you can either add directly to the pom;

    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy-jsonb</artifactId>
    </dependency>

or via the command line;

mvn quarkus:add-extension -Dextensions="io.quarkus:quarkus-resteasy-jsonb"

John


--

JOHN O'HARA

PRINCIPAL SOFTWARE ENGINEER

Red Hat

Guillaume Smet

unread,
Mar 16, 2019, 9:08:41 AM3/16/19
to John O'Hara, tsegi...@gmail.com, Quarkus Development mailing list
Hi John,

The issue is a bit different here because the objects are JSON objects specific to Vert.x. They are not handled by the resteasy-jsonb extension.

So he needs to declare his specific providers somehow. As mentioned previously, the service file is a very valid option.

Another option would be to produce `ResteasyJaxrsProviderBuildItem`s as it is done in the OpenTracing extension but the service file is a bit less intrusive.

And you even have a third option: if you add an empty META-INF/beans.xml file (you can find examples in the codebase) to your extension, your classes will be indexed and the providers will then be discovered by the RESTEasy extension.

--
Guillaume




John O'Hara

unread,
Mar 16, 2019, 10:54:03 AM3/16/19
to Guillaume Smet, tsegi...@gmail.com, Quarkus Development mailing list
Ah, sorry. didn't notice is was regarding vert.x

John

Thomas SEGISMONT

unread,
Mar 17, 2019, 6:02:18 PM3/17/19
to Guillaume Smet, Quarkus Development mailing list
Thanks Guillaume. I tried with the service file and it works nicely. And, as you said, it's intrusive. I will prepare a proper pull request tomorrow.

Cheers,
Thomas

Thomas SEGISMONT

unread,
Mar 18, 2019, 5:39:29 AM3/18/19
to Quarkus Development mailing list
Guillaume, John,


The test passes on my box in both regular and native mode.

I noticed this warning in the build logs though:

[WARNING] [io.quarkus.deployment.steps.ReflectiveHierarchyStep] Unable to properly register the hierarchy of the following classes for reflection as they are not in the Jandex index:
    - io.vertx.core.json.JsonArray
    - io.vertx.core.json.JsonObject
Consider adding them to the index either by creating a Jandex index for your dependency or via quarkus.index-dependency properties.

I searched for quarkus.index-dependency in the codebase without success. I'm not really sure what's the problem.

Thanks
Reply all
Reply to author
Forward
0 new messages