9. JsonBuilderのリストでClosure指定が可能に
例:リスト内Songの値はtitleだけ出力したい
class Song { String title … }
def mySongs = [new Song (title: "Title 1", …),
new Song (title: "Title 2", …), …]
JsonBuilder json = new JsonBuilder()
def map = json {
//今まで
songs mySongs.collect { Song s ->
json { title s.title }
}
}
2015-3-13 9
10. JsonBuilderのリストでClosure指定が可能に
例:リスト内Songの値はtitleだけ出力したい
class Song { String title … }
def mySongs = [new Song (title: "Title 1", …),
new Song (title: "Title 2", …), …]
JsonBuilder json = new JsonBuilder()
def map = json {
//2.3から
songs mySongs, { Song s ->
title s.title
}
}
2015-3-13 10