Java Reference
In-Depth Information
The JAX-RS annotations are easy enough to use. Building a URL-driven API with them
isn't difficult. The 2.0 version of the spec also includes a client-side API, but that's not
shown here.
Lessons learned (JAX-RS)
1. JAX-RS 2.0 is part of the Java EE specification and, like most of the recent specs,
is annotation-based.
2. It's very easy to build a hyperlink-driven database using JAX-RS.
3. Hypermedia mechanisms do exist in JAX-RS, but they're well hidden.
Instead, I want to illustrate the Groovy implementation of the same specifications, mostly
to illustrate the code simplifications. After that I'll deal with the issue of hypermedia.
9.3. Implementing JAX-RS with Groovy
Groovy doesn't change JAX-RS in any fundamental way, though as usual it simplifies the
implementation classes. JAX-RS is already simplifying the implementation by providing
its own kind of DSL, so the Groovy modifications are minimal.
The previous section used Groovy implementations but didn't present them. Here I'll show
just enough to illustrate the Groovy features.
To begin, here's the Person POGO. Note the @XmlRootElement annotation, used to
control the serialization of the Person for the response. Normally that's used for Java API
for XML Binding (JAXB), but the presence of the Jackson JSON parser causes the serial-
ization process to produce JSON objects instead:
@XmlRootElement
@EqualsAndHashCode
class Person {
Long id
String first
String last
String toString() { "$first $last" }
}
Search WWH ::




Custom Search