Search

Chapter 21. YAML Provider

download PDF
Since Beta 6, RESTEasy includes built-in support for YAML with the JYAML library. To enable YAML support, add the jyaml-1.3.jar to RESTEasy's classpath.
The JYAML JAR can be downloaded from SourceForge.
If you use Maven, the JYAML JAR is available through the main repositories, and included with the following dependency:
 <dependency>
<groupId>org.jyaml</groupId>
<artifactId>jyaml</artifactId>
<version>1.3</version>
 </dependency>
When starting up RESTEasy, watch the logs for a line stating that the YamlProvider has been added — this indicates that RESTEasy has located the JYAML JAR:
2877 Main INFO org.jboss.resteasy.plugins.providers.RegisterBuiltin - Adding YamlProvider
The YAML provider recognises three MIME types:
  • text/x-yaml
  • text/yaml
  • application/x-yaml
You can use YAML in a resource method like so:
 import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;

 @Path("/yaml")
 public class YamlResource
 {

@GET
@Produces("text/x-yaml")
public MyObject getMyObject() {
   return createMyObject();
}
...
 }
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.