Chapter 21. YAML Provider

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 recognizes 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();
}
...
 }