How do I return an object in JAX-RS as YAML using Jackson in Quarkus?

Viewed 443

I created a Quarkus project using https://code.quarkus.io (with RESTEasy Jackson extension), a Greeting class defined as:

public class Greeting {

    private final String message;

    public Greeting(String message) {
        this.message = message;
    }

    public String getMessage() {
        return message;
    }
}

And a JAX-RS endpoint to return it as YAML, so I wrote the following code:

@Path("/greeting")
public class GreetingResource {

    @GET
    @Produces("application/yaml")
    public Greeting hello() {
        return new Greeting("hello");
    }

}

I also added the following dependency to my Quarkus project to return YAML:

    <dependency>
      <groupId>com.fasterxml.jackson.jaxrs</groupId>
      <artifactId>jackson-jaxrs-yaml-provider</artifactId>
    </dependency>

However when I hit the endpoint, the following error is shown:

2020-05-22 10:55:55,693 ERROR [org.jbo.res.res.i18n] (executor-thread-1) RESTEASY002010: Failed to execute: javax.ws.rs.NotSupportedException: RESTEASY003200: Could not find message body reader for type: class org.acme.sample.Greeting of content type: application/yaml; charset=ISO-8859-1

What's the recommended way to fix this?

1 Answers

Besides adding the dependency in your pom.xml, make sure to also add the following to your application.properties:

quarkus.index-dependency.yaml.group-id=com.fasterxml.jackson.jaxrs
quarkus.index-dependency.yaml.artifact-id=jackson-jaxrs-yaml-provider
Related