(Quick Reference)

9.1.6.3 Using Named Configurations for Object Marshallers - Reference Documentation

Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith, Lari Hotari

Version: 3.0.12

9.1.6.3 Using Named Configurations for Object Marshallers

It is also possible to register named configurations. For example:

XML.createNamedConfig('publicApi') {
  it.registerObjectMarshaller(Book) { Book book, XML xml ->
    // do public API
  }
}
XML.createNamedConfig('adminApi') {
  it.registerObjectMarshaller(Book) { Book book, XML xml ->
    // do admin API
  }
}

Then when you use either the render or respond methods you can wrap the call in a named configuration if necessary to customize rendering per request:

XML.use( isAdmin ? 'adminApi' : 'publicApi') {
    render book as XML
}

or

XML.use( isAdmin ? 'adminApi' : 'publicApi') {
    respond book 
}