Java Reference
In-Depth Information
Listing 9.9. Using a JsonBuilder to produce nested links
One special quirk is notable here. The method calls toString on the individual Link in-
stances. As the JavaDocs for Link make clear, the toString and valueOf(String)
methods in Link are used to convert to and from strings.
The MessageBodyReader interface is quite similar. In that case there are only two
methods: isReadable and readFrom . The implementation of isReadable is the
same as the isWriteable method:
public boolean isReadable(Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType) {
type == Person && mediaType == MediaType.APPLICATION_JSON_TYPE
}
The readFrom method uses a JsonSlurper to convert string input into a Person , as
shown in the next listing.
Search WWH ::




Custom Search