Java Reference
In-Depth Information
Embedding Links in XML
The Link class also contains a JAXB XmlAdapter so that you can embed links within a
JAXB class. For example, let's take our familiar Customer domain class and enable it to add
one or more embedded links:
import
import javax.ws.rs.core.Link
javax.ws.rs.core.Link ;
@XmlRootElement
public
public class
class Customer
Customer {
private
private String name ;
private
private List < Link > links = new
new ArrayList < Link >();
@XmlElement
public
public String getName ()
{
return
return name ;
}
public
public void
void setName ( String name )
{
this
this . name = name ;
}
@XmlElement ( name = "link" )
XmlJavaTypeAdapter ( Link . JaxbAdapter . class )
public
public List < Link > getLinks ()
{
return
return links ;
}
}
You can now build any links you want and add them to the Customer domain class. They
will be converted into XML elements.
Wrapping Up
In this chapter, we discussed how links and forms have allowed the Web to scale. You
learned the advantages of applying HATEOAS to RESTful web service design. Finally, you
saw some JAX-RS utilities that can help make enabling HATEOAS in your JAX-RS services
easier. Chapter 24 contains some code you can use to test-drive many of the concepts in this
chapter.
Search WWH ::




Custom Search