Java Reference
In-Depth Information
Listing 8.17. A portion of the method that converts JSON movies to Movie instances
static Movie fromJSON(data) {
Movie m = new Movie()
m.id = data.id.toLong()
m.title = data.title
m.year = data.year.toInteger()
switch (data.mpaa_rating) {
case 'PG-13' : m.mpaaRating = MPAARating.PG_13; break
case 'NC-17' : m.mpaaRating = MPAARating.NC_17; break
default :
m.mpaaRating = MPAARating.valueOf(data.mpaa_rating)
}
m.runtime = data.runtime
m.criticsConsensus = data.critics_consensus ?: ''
The complete listing can be found in the topic source code but isn't fundamentally different
from what's being shown here.
A test to prove the conversion is working is shown in the following listing.
Search WWH ::




Custom Search