In a controller, how can I redirect json view output to a file instead of to the http response?
Grails 3.2.5.
Another simple option would be:
def action() { def json = [ key1:'value1', key2:[ key21:'value21' ] new File( '/the/path' ).withOutputStream{ it << ( json as JSON ) } [ some:result ] }
You can do something like this...
@Autowired JsonViewTemplateEngine templateEngine void myMethod() { Template t = templateEngine.resolveTemplate('/book/show') def writable = t.make(book: new Book(title:"The Stand")) def fw = new FileWriter(...) writable.writeTo( fw ) ... }
Copyright © 2021 Jogjafile Inc.
Another simple option would be: