Java Reference
In-Depth Information
long id
String title
int year
MPAARating mpaaRating
int runtime
String criticsConsensus
Map releaseDates = [:]
Map<String, Rating> ratings = [:]
String synopsis
Map posters = [:]
List<CastMember> abridgedCast = []
Map links = [:]
}
The Movie class has attributes for each contained element, with the data types specified.
It contains maps for the release dates, posters, ratings, and additional links, and a list for
the abridged cast. A CastMember is just a POGO:
class CastMember {
String name
long id
List<String> characters = []
}
A Rating holds a string and an integer:
class Rating {
String rating
int score
}
Just to keep things interesting, the MPAA rating is a Java enum , though it could just as
easily have been implemented in Groovy:
public enum MPAARating {
G, PG, PG_13, R, X, NC_17, Unrated
}
Converting a JSON movie to a Movie instance is done through a static method in the
Movie class. A portion of the fromJSON method is shown in the next listing.
Search WWH ::




Custom Search