0

I'm writing a POC for Quarkus. I'm using this quick start guide to build a REST client. The REST service I'll be integrating with is third party. Here is a simple example of my current implementation:

@Path("/v1")
@RegisterRestClient
public class EmployeeApi {

    @POST
    @Path("/employees")
    ApiResponse createEmployee(@RequestBody Employee employee)
}

This works fine. The issue I'm having is that the third party API will, depending on success / failure, return a response body. In the scenario it does fail, it provides details in the response body (ApiResponse) on why it was unsuccessful. When it succeeds, it returns nothing. This causes Quarkus to throw the following exception:
javax.ws.rs.ProcessingException: RESTEASY003145: Unable to find a MessageBodyReader of content-type application/octet-stream and type com.test.app.ApiResponse

I've tried to wrap ApiResponse in an Optional type but does not solve the problem. I see absolutely nothing in Quarkus / RESTEasy documentation that would indicate a work-around.

I'm wondering if I should be using javax.ws.rs.core.Response instead.

user0000001
  • 2,092
  • 2
  • 20
  • 48

1 Answers1

0

The problem is JaxRS tries to fit ApiResponse to a default return type being application/octet-stream

You should make sure to specify explicitly that you're returning application/json

This is possible using @Produces(APPLICATION_JSON) on top of your service.


Here is the correct code snippet

@Path("/v1")
@RegisterRestClient
public class EmployeeApi {

    @POST
    @Path("/employees")
    @Produces(APPLICATION_JSON)
    ApiResponse createEmployee(@RequestBody Employee employee)
}
Yassin Hajaj
  • 21,337
  • 9
  • 51
  • 89
  • APPLICATION_JSON is now the default (as of quarkus 1.10), so no need to specify it if this is what you need. The problem here is that the third party API is apparently returning a content-type of application/octet-stream when quarkus expects application/json. Either specify the right content-type with @Produces, or check why the API returns octet-stream when you expect some json. – Fab Apr 06 '21 at 22:19