Red Hat Training

A Red Hat training course is available for Red Hat JBoss Enterprise Application Platform

15.15. YAML Provider

RESTEasy comes with built in support for YAML using the SnakeYAML library. To enable YAML support, you must insert the following dependencies into the project pom file of your application:
<dependency>
	<groupId>org.jboss.resteasy</groupId>
	<artifactId>resteasy-yaml-provider</artifactId>
	<version>${version.org.jboss.resteasy}</version>
	<scope>provided</scope>
</dependency>

<dependency>
	<groupId>org.yaml</groupId>
	<artifactId>snakeyaml</artifactId>
	<version>${version.org.yaml.snakeyaml}</version>
</dependency>
YAML provider recognizes three mime types:
  • text/x-yaml
  • text/yaml
  • application/x-yaml
The following example demonstrates how to use YAML in a resource method:
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();
}
...
 }