Created
November 5, 2011 08:35
-
-
Save toby55kij/1341278 to your computer and use it in GitHub Desktop.
groovy.json.StreamingJsonBuilderのサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//StreamingJsonBuilderのサンプル | |
import groovy.json.JsonOutput | |
import groovy.json.StreamingJsonBuilder | |
def data = { | |
people { | |
person { | |
firstName 'Yasuharu' | |
lastName 'Hayami' | |
// Named arguments are valid values for objects too | |
address( | |
city: 'Niigata', | |
country: 'Japan', | |
zip: 9501115 | |
) | |
married false | |
// a list of values | |
conferences 'JGGUG', 'JJUG' | |
} | |
} | |
} | |
//StringWriterを使う | |
def writer = new StringWriter() | |
//StreamingJsonBuilderを使う | |
def builder = new StreamingJsonBuilder(writer) | |
builder data | |
println writer.toString() | |
//結果が等しいことを確認 | |
assert writer.toString() == JsonOutput.toJson(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment