Search code examples
jsongrailshateoas

Configure HAL JSON renderer for Grails 2.4.X


I am starting with HAL Json on Grails 2.4.X.

I saw i have to include to bean definition in spring resources for each domain entity like:

halClientRenderer(HalJsonRenderer, Client)
halClientCollectionRenderer(HalJsonCollectionRenderer, Client)

I may want to avoid this since i will end up with huge buggy resources file ... is it possible to avoid this?


Solution

  • In general this is the correct way to handle registering custom renders. It may seem prone to issues and results in a large Resources.groovy file, but if you have a large number of them you may want to consider creating something to manage them, such as using a factory bean/pattern.

    This blog post, may give you some additional ideas since it demonstrates using a single class to collect the individual renders and provides a single point to execute registering them from your Spring context.