Skip to content

Instantly share code, notes, and snippets.

@mattn
Created November 7, 2015 15:53
Show Gist options
  • Save mattn/e1fb3df8f47697f68887 to your computer and use it in GitHub Desktop.
Save mattn/e1fb3df8f47697f68887 to your computer and use it in GitHub Desktop.
@Grab('com.sparkjava:spark-core:2.1')
import static spark.Spark.*
import groovy.json.JsonBuilder
Object.metaClass.asJson = {
def builder = new JsonBuilder(delegate);
builder.toString()
}
def map = [:]
map['foo'] = 'ハローワールド'
map['bar'] = [1, 2, 3]
map['boo'] = ['hoge' : 'aaa', 'fuga' : [1, 2, ['obj':true]]]
get('/map', { req, res -> map.asJson() })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment