title: How to create a JSON view from a domain object?
body: <p>I'm creating the server side implementation of an AJAX based web application, where the client side receives responses that are domain objects serialized as JSON.  In order to provide a common look and feel, I would like to create templates for different types of domain objects, and re-use these as Spring views for multiple controllers.  </p>
  
  <p>For instance, say I have the following object graph:</p>
  
  <p>A - B - C</p>
  
  <p>where A and C have a many-to-many relationship.  When I return an object of type A as the result of an AJAX request, I would like to return its associated data in the B and C tables.  However, when I return an object of type C as the result, I would like to return just the data in table C. </p>
  
  <p>Thus far the only solution I have found is to create a custom data binder in the controller; however I believe this use case is better suited as a view that can be shared among many controllers.  Does a solution for this exist?</p>