Groovy - Convert object to JSON string

后端 未结 3 914
灰色年华
灰色年华 2021-01-30 12:23

I\'m pretty used to Grails converters, where you can convert any object to a JSON representation just like this (http://grails.org/Converters+Reference)

return f         


        
3条回答
  •  天涯浪人
    2021-01-30 12:47

    Do you mean like:

    import groovy.json.*
    
    class Me {
        String name
    }
    
    def o = new Me( name: 'tim' )
    
    println new JsonBuilder( o ).toPrettyString()
    

提交回复
热议问题