/ Published in: Groovy
Expected Behaviour
- Both classes should be rendered in the specified custom format when
store/book/list.jsonis loaded. - Order of how the marshallers are added should not matter.
- It should be possible to register more than one custom object marshallers.
- Only the first registered marshaller is picked up as expected.
- The second one is ignored and the default JSON generated by Grails is returned.
- The order of the calls to
registerObjectMarshallermatters, such that if the Book marshaller is added first, that one works. However if the Author marshaller is first, that one works.
Expand |
Embed | Plain Text
/* Book domain class */ int pages String title } /* Author domain class */ class Author { String name Date birthDate } /* registering custom marshallers in Bootstrap.groovy */ import grails.converters.JSON class BootStrap { JSON.registerObjectMarshaller(Author){ author, json -> json.build{ "class(author)" id(author.id) name(author.name) info{ birthdate(year: birthday.year, month: birthday.month, day: birthday.day) } } } json.build{ "class(book)" id(book.id) info{ pages(book.pages) } } } } } /* code for output in controller */ withFormat{ json{ render authors as JSON } html{ } } }
You need to login to post a comment.
